From 983e97c5055f1ccf7059f00215cc6e026ebc1ba0 Mon Sep 17 00:00:00 2001 From: Mats Lindh Date: Mon, 3 Oct 2011 15:26:34 +0200 Subject: [PATCH] Added convenience function for retrieving the status of a task by just submitting the task handle. To be able to query the correct server for the status, this requires the client to only have one added server. --- gearman/client.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gearman/client.py b/gearman/client.py index 8b798e8..7e2bb47 100644 --- a/gearman/client.py +++ b/gearman/client.py @@ -4,7 +4,7 @@ import os import random -import gearman.util +import gearman.util, gearman.job from gearman.connection_manager import GearmanConnectionManager from gearman.client_handler import GearmanClientCommandHandler @@ -122,6 +122,17 @@ def continue_while_jobs_incomplete(any_activity): return job_requests + def get_job_status_handle(self, handle, poll_timeout=None): + """Fetch the job status from a specific handle, if the Client only has one server added""" + assert type(len(self.connection_list) == 1), "Querying for job status by handle can only be performed with only one added server." + + # create a job to perform the status fetch + job = gearman.job.GearmanJob(self.connection_list[0], handle, None, None, None) + job_request = gearman.job.GearmanJobRequest(job) + job_request.state = 'CREATED' + + return self.get_job_status(job_request, poll_timeout) + def get_job_status(self, current_request, poll_timeout=None): """Fetch the job status of a single request""" request_list = self.get_job_statuses([current_request], poll_timeout=poll_timeout)