Factor out call string.

main
Vincent Driessen 13 years ago
parent 2ec12f1775
commit 8678f26df0

@ -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 '<Job %s(%s)>' % (
self.func.__name__,
', '.join(arg_list))
return '<Job %s>' % self.call_string
@total_ordering

@ -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()

Loading…
Cancel
Save