gearman background後臺job狀態獲取

GearmanClient background job有一個方法叫:php

public array GearmanClient::jobStatus ( string $job_handle )python

Get the status of a background jobide

返回值:函數

An array containing status information for the job corresponding to the supplied job handle. The first array element is a boolean indicating whether the job is even known, the second is a boolean indicating whether the job is still running, and the third and fourth elements correspond to the numerator and denominator of the fractional completion percentage, respectively.post

example:Monitor the status of a long running background jobui

<?php

/* create our object */
$gmclient= new GearmanClient();

/* add the default server */
$gmclient->addServer();

/* run reverse client */
$job_handle = $gmclient->doBackground("reverse", "this is a test");

if ($gmclient->returnCode() != GEARMAN_SUCCESS)
{
  echo "bad return code\n";
  exit;
}

$done = false;
do
{
   sleep(3);
   $stat = $gmclient->jobStatus($job_handle);
   if (!$stat[0]) // the job is known so it is not done
      $done = true;
   echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
}
while(!$done);

echo "done!\n";

?>

問題是這個函數必須得到job_handle,在php官方文檔裏面找了好久沒找到如何得到一個job_handle.this

在stackoveflow看了好久,找到一個問題回答:spa

 http://stackoverflow.com/questions/20563424/gearman-receive-data-of-processed-task.net

from irc, and looking at some python answers (http://stackoverflow.com/a/8349166/487878) I noticed that you could not get the data of a processed task from gearmand.rest

Either we want to store the data once it is processed by gearman worker and get the data back on the next call.

But you could not store the task handle and quit the client and try again with another client after the task is finished at gearman worker.

Before the worker finished you may get the response, but not after that. Hope that helps someone.

 

http://stackoverflow.com/questions/8344561/python-gearman-get-data-from-background-task

background tasks are called such because they allow the client that submitted them to un-block and work disconnected. They do not keep a channel of communication open to the client, so you won't get any of those status updates. They essentially go into the bit-bucket. If you want a background task to communicate its progress, you need to have some other channel for it to communicate with interested programs.

If you want the client to keep running and get updates, but not block on them, you can use the "task" method where you add a bunch of tasks, and then wait for any of them to provide status or be completed. I'm not sure if the pure python gearman interface has this, but the libgearman interface does. Its available in source form here https://launchpad.net/gearman-interface or in some versions of Ubuntu/Debian as python-gearman.libgearman.

 一個比較好的回答:

http://stackoverflow.com/questions/11615941/gearman-is-there-still-no-way-to-retrieve-custom-data-from-a-background-worker

相關文章
相關標籤/搜索