Replace "timeout" argument in queue.enqueue() with "job_timeout" (#1010)

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

@ -291,7 +291,12 @@ class Queue(object):
# Detect explicit invocations, i.e. of the form: # Detect explicit invocations, i.e. of the form:
# q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30) # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30)
timeout = kwargs.pop('job_timeout', None)
if timeout is None:
timeout = kwargs.pop('timeout', None) timeout = kwargs.pop('timeout', None)
if timeout:
warnings.warn('The `timeout` keyword is deprecated. Use `job_timeout` instead', DeprecationWarning)
description = kwargs.pop('description', None) description = kwargs.pop('description', None)
result_ttl = kwargs.pop('result_ttl', None) result_ttl = kwargs.pop('result_ttl', None)
ttl = kwargs.pop('ttl', None) ttl = kwargs.pop('ttl', None)

@ -319,12 +319,21 @@ class TestQueue(RQTestCase):
self.assertEqual(job.meta['foo'], 'bar') self.assertEqual(job.meta['foo'], 'bar')
self.assertEqual(job.meta['baz'], 42) self.assertEqual(job.meta['baz'], 42)
def test_job_timeout(self):
"""Timeout can be passed via job_timeout argument"""
queue = Queue()
job = queue.enqueue(echo, 1, timeout=15)
self.assertEqual(job.timeout, 15)
job = queue.enqueue(echo, 1, job_timeout=15)
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()
# Implicit args/kwargs mode # Implicit args/kwargs mode
job = q.enqueue(echo, 1, timeout=1, result_ttl=1, bar='baz') job = q.enqueue(echo, 1, job_timeout=1, result_ttl=1, bar='baz')
self.assertEqual(job.timeout, 1) self.assertEqual(job.timeout, 1)
self.assertEqual(job.result_ttl, 1) self.assertEqual(job.result_ttl, 1)
self.assertEqual( self.assertEqual(
@ -337,7 +346,7 @@ class TestQueue(RQTestCase):
'timeout': 1, 'timeout': 1,
'result_ttl': 1, 'result_ttl': 1,
} }
job = q.enqueue(echo, timeout=2, result_ttl=2, args=[1], kwargs=kwargs) job = q.enqueue(echo, job_timeout=2, result_ttl=2, args=[1], kwargs=kwargs)
self.assertEqual(job.timeout, 2) self.assertEqual(job.timeout, 2)
self.assertEqual(job.result_ttl, 2) self.assertEqual(job.result_ttl, 2)
self.assertEqual( self.assertEqual(

@ -257,7 +257,7 @@ class TestWorker(RQTestCase):
for timeout, expected_heartbeats in [(2, 0), (7, 1), (12, 2)]: for timeout, expected_heartbeats in [(2, 0), (7, 1), (12, 2)]:
job = q.enqueue(long_running_job, job = q.enqueue(long_running_job,
args=(timeout,), args=(timeout,),
timeout=30, job_timeout=30,
result_ttl=-1) result_ttl=-1)
with mock.patch.object(w, 'heartbeat', wraps=w.heartbeat) as mocked: with mock.patch.object(w, 'heartbeat', wraps=w.heartbeat) as mocked:
w.execute_job(job, q) w.execute_job(job, q)
@ -392,7 +392,7 @@ class TestWorker(RQTestCase):
# Put it on the queue with a timeout value # Put it on the queue with a timeout value
res = q.enqueue(create_file_after_timeout, res = q.enqueue(create_file_after_timeout,
args=(sentinel_file, 4), args=(sentinel_file, 4),
timeout=1) job_timeout=1)
try: try:
os.unlink(sentinel_file) os.unlink(sentinel_file)
@ -543,7 +543,7 @@ class TestWorker(RQTestCase):
worker = SimpleWorker([queue]) worker = SimpleWorker([queue])
job_timeout = 300 job_timeout = 300
job = queue.enqueue(save_key_ttl, worker.key, timeout=job_timeout) job = queue.enqueue(save_key_ttl, worker.key, job_timeout=job_timeout)
worker.work(burst=True) worker.work(burst=True)
job.refresh() job.refresh()
self.assertGreater(job.meta['ttl'], job_timeout) self.assertGreater(job.meta['ttl'], job_timeout)

Loading…
Cancel
Save