简体   繁体   English

如何通过uniq id获取Gearman Jobs的状态?

[英]How to get status of Gearman Jobs by their uniq id?

I need to get status of Gearman jobs by these uniq id, not by open handlers, as desribed every place I seen 我需要通过这些uniq id获取Gearman作业的状态,而不是通过开放处理程序获取,就像我看到的每个地方所描述的那样

Is it possible? 可能吗? using in python-gearman v. 2... 在python-gearman v.2中使用...

Thanks for assistance! 谢谢你的帮助!

Had to dig quite a bit to solve this issue, as it's not exposed in a friendly manner in the python-gearman-API. 不得不花费很多东西来解决这个问题,因为它没有以友好的方式暴露在python-gearman-API中。 You can however solve it by creating appropriate instances of the GearmanJob and GearmanJobRequest yourself. 但是,您可以通过自己创建GearmanJobGearmanJobRequest适当实例来解决它。

Here's a small example of how you can do this: 这是一个如何做到这一点的小例子:

import gearman

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

You want to keep track of which server got to handle the job (if you have more than one Gearman server handling tasks), and the handle of the task. 您希望跟踪哪个服务器处理该作业(如果您有多个Gearman服务器处理任务),以及任务的句柄。 The connection information is available through result.job.connection ( .gearman_host and .gearman_port ), while the handle is available through result.job.handle . 连接信息可通过result.job.connection.gearman_host.gearman_port ),而手柄,可通过result.job.handle

To check the status of a currently running job you create a GearmanClient , but only supply the server you want to query for the current state: 要检查当前正在运行的作业的状态,请创建GearmanClient ,但仅提供要查询当前状态的服务器:

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))

Hopefully that helps! 希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM