Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Add method for retrieving status of a running task #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion gearman/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit like a hack. It looks like you've gotten the handle from GearmanJobRequest.handle and want to check on the status, but for some reason you don't have the GearmanJobRequest anymore.

My main objection here is the 1 connection limitation. I think you should try and rewrite this to poll all the connections, but maybe it'd be better if you kept track of the GearmanJobRequest objects, unless you have some external requirement to not store python objects, but only handles ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In it's current form it's a bit of a hack, yes. :-) I'm not too fond of storing the complete GermanJobRequest in a DB - there will be use cases where you want to simply poll a server (or a collection of servers) for the state of a job (from the CLI, for example) and don't have access to the complete GearmanJobRequest object.

Since an handle isn't unique to a host in Gearman (as duplicate local host names will generate the same handles across servers), I decided to use the server address provided to the client itself to inidicate which Gearman server to query for the status of the task. The idea (if I remember correctly) was to allow a client user to query the status of a task by creating a client with the gearman server to query, and then request the status of a handle from that server.

Polling all the connections are a possibility, but might return the wrong task if you have several servers with the same local host name - so either we're talking about a documentation issue (by polling all the connections) or a code issue (by only allowing the user of the library to set which server to poll). The last case solves the issue where you could store the (server, handle) pair in a DB and then request the job status at some point in time. I'm open for both, as long as the limitations are clear for the user.


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)
Expand Down