diff --git a/rq/queue.py b/rq/queue.py index 2116e50..090576d 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -64,7 +64,7 @@ class Queue(object): prefix = self.redis_queue_namespace_prefix self.name = name self._key = '{0}{1}'.format(prefix, name) - self._default_timeout = parse_timeout(default_timeout) + self._default_timeout = parse_timeout(default_timeout) or self.DEFAULT_TIMEOUT self._is_async = is_async if 'async' in kwargs: @@ -330,7 +330,7 @@ class Queue(object): job.enqueued_at = utcnow() if job.timeout is None: - job.timeout = self.DEFAULT_TIMEOUT + job.timeout = self._default_timeout job.save(pipeline=pipe) job.cleanup(ttl=job.ttl, pipeline=pipe) diff --git a/tests/test_queue.py b/tests/test_queue.py index 20a051c..2a6c46e 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -327,6 +327,24 @@ class TestQueue(RQTestCase): job = queue.enqueue(echo, 1, job_timeout=15) self.assertEqual(job.timeout, 15) + + def test_default_timeout(self): + """Timeout can be passed via job_timeout argument""" + queue = Queue() + job = queue.enqueue(echo, 1) + self.assertEqual(job.timeout, queue.DEFAULT_TIMEOUT) + + job = Job.create(func=echo) + job = queue.enqueue_job(job) + self.assertEqual(job.timeout, queue.DEFAULT_TIMEOUT) + + queue = Queue(default_timeout=15) + job = queue.enqueue(echo, 1) + self.assertEqual(job.timeout, 15) + + job = Job.create(func=echo) + job = queue.enqueue_job(job) + self.assertEqual(job.timeout, 15) def test_enqueue_explicit_args(self): """enqueue() works for both implicit/explicit args."""