Gearman addTaskBackground完整回调没有火 [英] Gearman addTaskBackground complete Callback doesnot fire

查看:650
本文介绍了Gearman addTaskBackground完整回调没有火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在后台做一些工作,并将结果写入完成回调的文件结果,但它的唯一的工作为addTask(不在后台),而不是 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

有人有任何想法吗?




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() . "\n", 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() . "\n";
        break;
    }
};

function uploader($job){

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


推荐答案

Complete.callback 不会在背景任务完成时调用。如果要检查后台作业的状态,请使用 GearmanClient :: jobStatus

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

Client.php

Client.php

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

Status.php

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] . "\n";

阅读更多此处

这篇关于Gearman addTaskBackground完整回调没有火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆