From abf688111401edcd659234d18631462eb6b9442b Mon Sep 17 00:00:00 2001 From: Wolfgang Langner Date: Sat, 23 Feb 2019 07:46:26 +0100 Subject: [PATCH] Fix #1040 queue default timeout bug. (#1042) Add test for queue default_timeout. --- rq/queue.py | 4 ++-- tests/test_queue.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 2116e50c..090576da 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 20a051c6..2a6c46e8 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."""