Added checks for 0 ttl (#1110)

main
Selwin Ong 6 years ago committed by GitHub
parent 8df4e8ecfa
commit b14c4e288d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -231,10 +231,19 @@ class Queue(object):
and kwargs as explicit arguments. Any kwargs passed to this function
contain options for RQ itself.
"""
timeout = parse_timeout(timeout) or self._default_timeout
timeout = parse_timeout(timeout)
if timeout is None:
timeout = self._default_timeout
elif timeout == 0:
raise ValueError('0 timeout is not allowed. Use -1 for infinite timeout')
result_ttl = parse_timeout(result_ttl)
failure_ttl = parse_timeout(failure_ttl)
ttl = parse_timeout(ttl)
if ttl is not None and ttl <= 0:
raise ValueError('Job ttl must be greater than 0')
job = self.job_class.create(
func, args=args, kwargs=kwargs, connection=self.connection,

@ -238,6 +238,12 @@ class TestQueue(RQTestCase):
)
self.assertEqual(q.count, 0)
def test_enqueue_with_ttl(self):
"""Negative TTL value is not allowed"""
queue = Queue()
self.assertRaises(ValueError, queue.enqueue, echo, 1, ttl=0)
self.assertRaises(ValueError, queue.enqueue, echo, 1, ttl=-1)
def test_enqueue_sets_status(self):
"""Enqueueing a job sets its status to "queued"."""
q = Queue()
@ -264,6 +270,13 @@ class TestQueue(RQTestCase):
job = queue.enqueue(echo, 1, job_timeout=15)
self.assertEqual(job.timeout, 15)
# Not passing job_timeout will use queue._default_timeout
job = queue.enqueue(echo, 1)
self.assertEqual(job.timeout, queue._default_timeout)
# job_timeout = 0 is not allowed
self.assertRaises(ValueError, queue.enqueue, echo, 1, job_timeout=0)
def test_default_timeout(self):
"""Timeout can be passed via job_timeout argument"""
queue = Queue()

Loading…
Cancel
Save