首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过Gearman作业的uniq id获取其状态?

如何通过Gearman作业的uniq id获取其状态?
EN

Stack Overflow用户
提问于 2011-08-08 22:44:15
回答 1查看 2.1K关注 0票数 9

我需要通过这些uniq id来获取Gearman作业的状态,而不是通过开放的处理程序,因为我看到的每个地方都有描述

有可能吗?在python-gearman v2中使用...

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2011-10-03 19:47:31

我花了很大力气来解决这个问题,因为它在python-gearman-API中不是以友好的方式公开的。但是,您可以通过自己创建适当的GearmanJobGearmanJobRequest实例来解决此问题。

下面是一个小示例,说明如何做到这一点:

代码语言:javascript
复制
import gearman

client = gearman.GearmanClient(['localhost'])
result = client.submit_job('reverse', 'this is a string', background=True);

您希望跟踪哪个服务器处理作业(如果有多个Gearman服务器处理任务),以及任务的句柄。连接信息可以通过result.job.connection (.gearman_host.gearman_port)获得,而句柄可以通过result.job.handle获得。

要检查当前正在运行的作业的状态,您可以创建一个GearmanClient,但只提供要查询当前状态的服务器:

代码语言:javascript
复制
client = gearman.GearmanClient(['localhost'])

# configure the job to request status for - the last four is not needed for Status requests.
j = gearman.job.GearmanJob(client.connection_list[0], result.job.handle, None, None, None, None)

# create a job request 
jr = gearman.job.GearmanJobRequest(j)
jr.state = 'CREATED'

# request the state from gearmand
res = client.get_job_status(jr)

# the res structure should now be filled with the status information about the task
print(str(res.status.numerator) + " / " + str(res.status.denominator))

希望这能有所帮助!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6983854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档