Frage

We're using Gearman and when do use methods like doLowBackground or doHigh, these all return a jobHandle, but when we do tasks there is no jobHandle object. We get the GearmanTask object, instead of getting the jobHandle, we get string(0) ""

Any ideas what could cause this?

Thank you!

EDIT: Here is the code and additional info:

// $client = \GearmanClient; // servers added, all that jazz
// $workload = 'string';

$arguments = array(
    'handleJob',
    $workload
);

$task = call_user_func_array(array($client, $method), $arguments);

if ($task instanceof GearmanTask) {
    $handles[] = $task->jobHandle();
}

$data = $client->runTasks();

The tasks run correctly but $handle is being populated with empty strings (one for each task added)

EDIT: This is the response we get:

object(GearmanTask)#294 (0) {
}

I've dumped every PECL gearman object, nothing ever displays, here's the client, populated with servers, options, etc

object(GearmanClient)#291 (0) {
}

Doesn't show anything.

War es hilfreich?

Lösung

A job handle is not assigned to a task until the task is received and queued by the Gearman job server.

However, you can use GearmanClient::setCreatedCallback() to get the handle once it has been queued. This must be done before both adding and running the tasks:

$client = new \GearmanClient();
$client->addServer('127.0.0.1');
$handles = array();

$client->setCreatedCallback(function (\GearmanTask $task) use (&$handles) {
    $handles[] = $task->jobHandle();
});

$client->addTask('functionName', 'workload'); // ...
$client->runTasks();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top