Store the job ID on the internal stack.

It does so instead of the instance itself.  Still returns the job---the
interface hasn't changed.
main
Vincent Driessen 12 years ago
parent 372de4b45a
commit 95d3aed98e

@ -57,7 +57,10 @@ def get_current_job():
"""Returns the Job instance that is currently being executed. If this
function is invoked from outside a job context, None is returned.
"""
return _job_stack.top
job_id = _job_stack.top
if job_id is None:
return None
return Job.fetch(job_id)
class Job(object):
@ -332,11 +335,11 @@ class Job(object):
# Job execution
def perform(self): # noqa
"""Invokes the job function with the job arguments."""
_job_stack.push(self)
_job_stack.push(self.id)
try:
self._result = self.func(*self.args, **self.kwargs)
finally:
assert self == _job_stack.pop()
assert self.id == _job_stack.pop()
return self._result

@ -209,4 +209,7 @@ class TestJob(RQTestCase):
# Executing the job function from outside of RQ throws an exception
job = Job.create(func=access_self)
self.assertEqual(job.perform(), job.id)
job.save()
id = job.perform()
self.assertEqual(job.id, id)
self.assertEqual(job.func, access_self)

Loading…
Cancel
Save