From f498de57b6abde0573985d0a509bb0a940026f89 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 25 Nov 2012 17:15:38 +0700 Subject: [PATCH] Always call job.save even on synchronous queues so get_current_job doesn't fail --- rq/queue.py | 2 +- tests/test_job.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rq/queue.py b/rq/queue.py index 7dd90d20..f130e5be 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -172,9 +172,9 @@ class Queue(object): job.timeout = timeout # _timeout_in_seconds(timeout) else: job.timeout = 180 # default + job.save() if self._async: - job.save() self.push_job_id(job.id) else: job.perform() diff --git a/tests/test_job.py b/tests/test_job.py index 8f59b797..13af0b5b 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -6,6 +6,7 @@ from tests.helpers import strip_milliseconds from cPickle import loads from rq.job import Job, get_current_job from rq.exceptions import NoSuchJobError, UnpickleError +from rq.queue import Queue class TestJob(RQTestCase): @@ -211,3 +212,10 @@ class TestJob(RQTestCase): id = job.perform() self.assertEqual(job.id, id) self.assertEqual(job.func, access_self) + + # Ensure that get_current_job also works from within synchronous jobs + queue = Queue(async=False) + job = queue.enqueue(access_self) + id = job.perform() + self.assertEqual(job.id, id) + self.assertEqual(job.func, access_self)