我需要通过这些uniq id来获取Gearman作业的状态,而不是通过开放的处理程序,因为我看到的每个地方都有描述
有可能吗?在python-gearman v2中使用...
感谢您的帮助!
发布于 2011-10-03 19:47:31
我花了很大力气来解决这个问题,因为它在python-gearman-API中不是以友好的方式公开的。但是,您可以通过自己创建适当的GearmanJob和GearmanJobRequest实例来解决此问题。
下面是一个小示例,说明如何做到这一点:
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,但只提供要查询当前状态的服务器:
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))希望这能有所帮助!
https://stackoverflow.com/questions/6983854
复制相似问题