zoukankan      html  css  js  c++  java
  • gearman background后台job状态获取

    GearmanClient background job有一个方法叫:

    public array GearmanClient::jobStatus ( string $job_handle )

    Get the status of a background job

    返回值:

    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.

    example:Monitor the status of a long running background job

    <?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
    ";
      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] . "
    ";
    }
    while(!$done);
    
    echo "done!
    ";
    
    ?>

    问题是这个函数必须获得job_handle,在php官方文档里面找了很久没找到如何获得一个job_handle.

    在stackoveflow看了很久,找到一个问题回答:

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

    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.

    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

  • 相关阅读:
    C# 安装包中添加卸载
    如何提取json里面的数据
    JSON写入
    在Net下处理Json
    Linq To Json
    衡量视频序列特性的TI(时间信息)和SI(空间信息)
    DotCMS安装步骤
    【12c OCP】最新CUUG OCP071考试题库(52题)
    【ocp12c】最新Oracle OCP071考试题库(44题)
    【Oracle 12c】最新CUUG OCP071考试题库(53题)
  • 原文地址:https://www.cnblogs.com/youxin/p/4152336.html
Copyright © 2011-2022 走看看