9
我需要通過這些uniq id獲取Gearman作業的狀態,而不是通過公開的處理程序,因爲我看過的每個地方都在描述如何通過uniq id獲取Gearman Jobs的狀態?
這可能嗎?在python-gearman v.2中使用...
感謝您的協助!
我需要通過這些uniq id獲取Gearman作業的狀態,而不是通過公開的處理程序,因爲我看過的每個地方都在描述如何通過uniq id獲取Gearman Jobs的狀態?
這可能嗎?在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);
你要跟蹤哪些服務器得到了處理工作(如果你有一個以上的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))
希望!
我還在github的python-gearman叉子中添加了一個方便的方法。我不認爲它會隨時在官方發佈,但補丁可以在這裏找到:https://github.com/matslindh/python-gearman/commit/983e97c5055f1ccf7059f00215cc6e026ebc1ba0 – MatsLindh
謝謝。它看起來像我需要的。但我解決它通過使用memcache包裝來存儲狀態和作業的其他數據。 –