From 8678f26df0384cd756d2f8220f42bdcea120dde0 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 21 Nov 2011 20:33:36 +0100 Subject: [PATCH] Factor out call string. --- rq/queue.py | 17 +++++++++++------ rq/worker.py | 10 +++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index d573eed..f4422db 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -56,13 +56,18 @@ class Job(object): """ return self.func(*self.args, **self.kwargs) + @property + def call_string(self): + """Returns a string representation of the call, formatted as a regular + Python function invocation statement. + """ + arg_list = map(repr, self.args) + arg_list += map(lambda tup: '%s=%r' % (tup[0], tup[1]), + self.kwargs.items()) + return '%s(%s)' % (self.func.__name__, ', '.join(arg_list)) + def __str__(self): - arg_list = map(repr, self.args) + \ - map(lambda tup: '%s=%r' % (tup[0], tup[1]), - self.kwargs.items()) - return '' % ( - self.func.__name__, - ', '.join(arg_list)) + return '' % self.call_string @total_ordering diff --git a/rq/worker.py b/rq/worker.py index 79e4272..e83927d 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -165,7 +165,7 @@ class Worker(object): self.state = 'idle' qnames = ', '.join(self.queue_names()) self.procline('Waiting on %s' % (qnames,)) - self.log.info('Watching queues: %s' % (qnames,)) + self.log.info('Waiting for jobs on %s' % (qnames,)) wait_for_job = not quit_when_done job = Queue.dequeue_any(self.queues, wait_for_job) if job is None: @@ -210,8 +210,12 @@ class Worker(object): os.waitpid(child_pid, 0) def perform_job(self, job): - self.procline('Processing %s from %s since %s' % (job.func.__name__, job.origin.name, time.time())) - msg = 'Processing job %s from queue %s' % (job, job.origin.name) + self.procline('Processing %s from %s since %s' % ( + job.func.__name__, + job.origin.name, time.time())) + msg = 'Processing job %s from queue %s' % ( + job.call_string, + job.origin.name) self.log.debug(msg) try: rv = job.perform()