2011-08-08 7 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 래퍼를 사용하여 문제를 해결했습니다. –

관련 문제