Omar Abid
Omar Abid

Reputation: 15976

How to set a timeout for a gearman job

I want to set a timeout duration for Gearman jobs. For instance, I don't want a gearman job to run for more than 30 seconds, and if the job is running for more than 30 seconds it should be stopped and the next job is started.

Is this possible with Gearman? (I'm using the Gearman PHP API on Centos 6.2)

Upvotes: 1

Views: 3555

Answers (1)

Baba
Baba

Reputation: 95121

What you are looking for is GearmanWorker::timeout here is a Good Example

//Set Timeout
$gmworker->setTimeout(5000);

echo "Waiting for job...\n";

// Start working 
while ( @$gmworker->work() || $gmworker->returnCode() == GEARMAN_TIMEOUT ) {
    if ($gmworker->returnCode() == GEARMAN_TIMEOUT) {
        // Normally one would want to do something useful here ...
        continue;
    }

    if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
        // Somthign failed
        break;
    }
}

Upvotes: 2

Related Questions