9

私が見たすべての場所で説明されているように、開いているハンドラーではなく、これらの一意の ID によって Gearman ジョブのステータスを取得する必要があります。

出来ますか?python-gearman v. 2 での使用...

助けてくれてありがとう!

4

1 に答える 1

6

この問題は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))

うまくいけば、それが役立ちます!

于 2011-10-03T11:47:30.577 に答える