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

Add test for queue default_timeout.
main
Wolfgang Langner 6 years ago committed by Selwin Ong
parent 1f3c9f6e59
commit abf6881114

@ -64,7 +64,7 @@ class Queue(object):
prefix = self.redis_queue_namespace_prefix prefix = self.redis_queue_namespace_prefix
self.name = name self.name = name
self._key = '{0}{1}'.format(prefix, 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 self._is_async = is_async
if 'async' in kwargs: if 'async' in kwargs:
@ -330,7 +330,7 @@ class Queue(object):
job.enqueued_at = utcnow() job.enqueued_at = utcnow()
if job.timeout is None: if job.timeout is None:
job.timeout = self.DEFAULT_TIMEOUT job.timeout = self._default_timeout
job.save(pipeline=pipe) job.save(pipeline=pipe)
job.cleanup(ttl=job.ttl, pipeline=pipe) job.cleanup(ttl=job.ttl, pipeline=pipe)

@ -328,6 +328,24 @@ class TestQueue(RQTestCase):
job = queue.enqueue(echo, 1, job_timeout=15) job = queue.enqueue(echo, 1, job_timeout=15)
self.assertEqual(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): def test_enqueue_explicit_args(self):
"""enqueue() works for both implicit/explicit args.""" """enqueue() works for both implicit/explicit args."""
q = Queue() q = Queue()

Loading…
Cancel
Save