Mic*_*III 9 python gearman python-gearman
我需要通过这些uniq id获取Gearman作业的状态,而不是通过开放处理程序获取,就像我看到的每个地方所描述的那样
可能吗?在python-gearman v.2中使用...
谢谢你的帮助!
不得不花费很多东西来解决这个问题,因为它没有以友好的方式暴露在python-gearman-API中.但是,您可以通过创建GearmanJob和您GearmanJobRequest自己的适当实例来解决它.
这是一个如何做到这一点的小例子:
import gearman
client = gearman.GearmanClient(['localhost'])
result = client.submit_job('reverse', 'this is a string', background=True);
Run Code Online (Sandbox Code Playgroud)
您希望跟踪哪个服务器处理该作业(如果您有多个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))
Run Code Online (Sandbox Code Playgroud)
希望这有帮助!