From 95d3aed98ee2b5cba6a0e92550c29efcbf245788 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sun, 2 Sep 2012 23:00:12 +0200 Subject: [PATCH] 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. --- rq/job.py | 9 ++++++--- tests/test_job.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/rq/job.py b/rq/job.py index 380783f..6faefa9 100644 --- a/rq/job.py +++ b/rq/job.py @@ -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 diff --git a/tests/test_job.py b/tests/test_job.py index 0d67a17..f75d878 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -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)