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\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.
在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
gearman background后台job状态获取的更多相关文章
- Asp.net中从后台中如何获取html控件
比如定义html的文本框如下: <input type="text" onclick="fun()" id="htmlTxtDate" ...
- 为什么JS动态生成的input标签在后台有时候没法获取到
最近在做一个产品添加的功能,需求有点奇葩,所以在添加的时候免不了要用到动态生成控件,然后我就使用了JS去动态生成一些 checkbox类型的input标签,在以前用asp.net在后台生成的input ...
- js前端对后台数据的获取,如果是汉字则需要添上引号
js前端对后台数据的获取,如果是汉字则需要添上引号
- Flink之状态之状态获取
1.什么是状态 对于任何一个操作,都可以被看成是一个函数,比如y=f(x),如果对于同一个x的任何一次输入,得到的y都是相同的,则可以认为这个函数是无状态,否则,这个函数就是有状态的.Flink的一大 ...
- Android输入法界面管理(打开/关闭/状态获取)
最近做一个带发表情的聊天界面,需要管理系统输入法的状态, 一.打开输入法窗口: InputMethodManager inputMethodManager = (InputMethodManager) ...
- C#调用windows api控制打印机 状态获取 打印 自定义纸张 完整版
using System; using System.Text; using System.Runtime.InteropServices; using System.Security; using ...
- jquery 访问后台方法 并且获取后方法返回的数据
说明: 1.开发环境 asp.net MVC4 c#语言. 后台方法位于控制器中ProController.cs中 后台方法如下: public string GetNumber() { string ...
- ASP.NET WebForm中JavaScript修改了页面上Label的值,如何在后台代码中获取
在用ASP.NET WebForm开发一个项目时,遇到如下的一个情况 页面上有一个Textbox控件,还有2个Label 控件. 当Textbox控件中的值更改时,两个Label控件上的值做相应的更改 ...
- 微信小程序通过getPhoneNumber后台PHP解密获取用户手机号码
之前做的版本用户这块是以获取用户openid为凭证,最近改版重新整理了一下,新增注册登录以手机号码为主, 两种(正常注册手机号码-密码+一键获取当前用户手机号码) getPhoneNumber这个组件 ...
随机推荐
- WebAssembly,Web的新时代
在浏览器之争中,Chrome凭借JavaScript的卓越性能取得了市场主导地位,然而由于javascript的无类型特性,导致其运行时消耗大量的性能做为代价,这也是JavaScript的瓶颈之一.W ...
- 做自己生活的导演:华为CameraKit为你加持大师光环
今年最流行的娱乐方式,无疑是短视频,抖音等短视频平台,越来越多的消费者沉浸其中.除了看别人拍的短视频用以丰富生活乐趣之外,也有不少跃跃欲试的消费者加入到短视频拍摄的行列中.随着拍摄者的增加,对拍摄设备 ...
- Linux中解压缩命令gzip和unzip的一点说明
inux中解压缩命令gzip和unzip的一点说明 转载 2014年10月29日 20:37:35 20741 Linux 常用的压缩命令有 gzip 和 zip,两种压缩包的结尾不同:zip 压 ...
- 挑战:万能的slash! 判断js中“/”是正则、除号、注释?
很久以前在其它地方就探讨和关注过这个问题,但都没有满意的解答. 看了zjfeihu 的帖子: <前端代码加亮插件(html,jss,css),支持即时加亮,运行代码>,再次提出这个比较经典 ...
- Struts2 异常处理
Struts提供了一个更简单的方式来处理未捕获的异常,并将用户重定向到一个专门的错误页面.您可以轻松地Struts配置到不同的异常有不同的错误页面. Struts的异常处理所使用的“exception ...
- 嵌入式开发之davinci--- 8168 总的roi 编码
http://bbs.61dsp.com/forum.php?mod=viewthread&tid=767
- js intanceof 或 typeof
typeof和instanceof的区别 typeof和instanceof都可以用来判断变量,它们的用法有很大区别: typeof会返回一个变量的基本类型,只有以下几种:number,boolean ...
- 怎么把顶部的Django administration去掉!!
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/contrib/admin/t ...
- PHP和Java 加解密
http://www.jb51.net/article/64961.htm http://www.jb51.net/article/129218.htm http://www.jb51.net/art ...
- SQL.Cookbook 读书笔记3 操作多个表
第三章 操作多个表 表连接的内连接和外连接 A表 B表id name id name 1 a 1 b 2 b 3 c4 c内连接就是左表和右表相同的数据,查询结果只有相等的数据:select * fr ...