Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Always call job.save even on synchronous queues so get_current_job do…

…esn't fail
  • Loading branch information...
commit f498de57b6abde0573985d0a509bb0a940026f89 1 parent 10237dd
@selwin selwin authored committed
Showing with 9 additions and 1 deletion.
  1. +1 −1  rq/queue.py
  2. +8 −0 tests/test_job.py
View
2  rq/queue.py
@@ -172,9 +172,9 @@ def enqueue_job(self, job, timeout=None, set_meta_data=True):
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()
View
8 tests/test_job.py
@@ -6,6 +6,7 @@
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 @@ def test_job_access_within_job_function(self):
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)

0 comments on commit f498de5

Please sign in to comment.
Something went wrong with that request. Please try again.