Fix #1040 queue default timeout bug. (#1042)

Add test for queue default_timeout.
This commit is contained in:
Wolfgang Langner 2019-02-23 07:46:26 +01:00 committed by Selwin Ong
parent 1f3c9f6e59
commit abf6881114
2 changed files with 20 additions and 2 deletions

View File

@ -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)

View File

@ -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."""