doufu8127 2014-02-09 06:54 采纳率: 100%
浏览 172
已采纳

Gearman addTaskBackground完成回调不会触发

I am trying to make some job in background and write result to file result from complete callback, but its only work for addTask (not in background) and not for addTaskBackground

have somebody any ideas?

thanks for help!

$client = new GearmanClient();

$client->addServer('localhost');

$client->setCompleteCallback("complete");
$client->addTaskBackground('upload', 'http://youtube.com/watch?v=o3mP3mJDL2k', null, 1);
$client->addTaskBackground('upload', 'http://www.youtube.com/watch?v=SgAVnlnf8w0', null, 2);

/* in these case complete callback works
$client->addTask('upload', 'http://youtube.com/watch?v=o3mP3mJDL2k');
$client->addTask('upload', 'http://www.youtube.com/watch?v=SgAVnlnf8w0');
*/

$client->runTasks();

function complete($task){
    file_put_contents('/home/vonica/public_html/test/tmp/1.txt', $task->unique() . ", " . $task->data() . "
", FILE_APPEND);
}
$worker = new GearmanWorker();
$worker->addServer('localhost');

$worker->addFunction('upload', 'uploader');

while($worker->work()){
    if ($worker->returnCode() != GEARMAN_SUCCESS) {
        echo "ret code: " . $worker->returnCode() . "
";
        break;
    }
};

function uploader($job){

   $content = $job->workload();
   exec ('echo $( youtube-dl -f worst "'.$content.'")');
   return $content;
}
  • 写回答

1条回答 默认 最新

  • duanmu2941 2014-02-10 03:54
    关注

    CompleteCallback will not be called on background task completion. If you want to check the status of background job use GearmanClient::jobStatus.

    Client.php

    // save this $job_handle somewhere
    $job_handle = $client->doBackground('upload', 'http://youtube.com/watch?v=o3mP3mJDL2k', null, 1);
    

    Status.php

    // use previously saved job handle to check job's status
    $job_handle = $_GET['job_handle'];
    $stat = $client->jobStatus($job_handle);
    echo "Running: " . 
         ($stat[1] ? "true" : "false") . 
         ", numerator: " . 
         $stat[2] . 
         ", denomintor: " . 
         $stat[3] . "
    ";
    

    Read more here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog