2011-08-08 9 views

答えて

6

python-gearman-APIで親しみやすい方法で公開されていないため、この問題を解決するためにかなり掘り下げていました。しかし、自分でGearmanJobGearmanJobRequestの適切なインスタンスを作成することで解決できます。

ここでは、この操作を行うことができる方法の小さな例です:あなたは(あなたが複数のGearmanサーバーの処理タスクを持っている場合)は、ジョブを処理するようになっているサーバーを追跡したい

import gearman 

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

、およびタスクのハンドル。接続情報は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)) 

うまくいけば役立ちます!

+0

私はgithubのpython-gearmanのフォークに便利なメソッドを追加しました。私はそれがいつでも正式な配布になるとは思わないが、パッチはここから入手できる:https://github.com/matslindh/python-gearman/commit/983e97c5055f1ccf7059f00215cc6e026ebc1ba0 – MatsLindh

+0

ありがとう。それは私が必要とするようなものです。しかし、私はmemcacheラッパーを使ってジョブのステータスと追加データを保存することで解決します。 –

関連する問題