From e6bb7de8c0bab01404c3ba64fc4599624b9cb468 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 23 Jul 2012 11:50:32 +0200 Subject: [PATCH] Get rid of the ambiguity when passing the timeout argument to .enqueue() calls. --- rq/queue.py | 17 ++++++++++------- tests/test_worker.py | 5 +++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index e87333fe..9253aa10 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -107,7 +107,7 @@ class Queue(object): """Pushes a job ID on the corresponding Redis queue.""" self.connection.rpush(self.key, job_id) - def enqueue_call(self, func, args, kwargs, **options): + def enqueue_call(self, func, args=None, kwargs=None, **options): """Creates a job to represent the delayed function call and enqueues it. @@ -138,12 +138,15 @@ class Queue(object): 'Functions from the __main__ module cannot be processed ' 'by workers.') - options = {} - try: - options['timeout'] = kwargs.pop('timeout') - except KeyError: - pass - return self.enqueue_call(func=f, args=args, kwargs=kwargs, **options) + # Warn about the timeout flag that has been removed + if 'timeout' in kwargs: + import warnings + warnings.warn('The use of the timeout kwarg is not supported ' + 'anymore. If you meant to pass this argument to RQ ' + '(rather than to %r), use the `.enqueue_call()` ' + 'method instead.' % f, DeprecationWarning) + + return self.enqueue_call(func=f, args=args, kwargs=kwargs) def enqueue_job(self, job, timeout=None, set_meta_data=True): """Enqueues a job for delayed execution. diff --git a/tests/test_worker.py b/tests/test_worker.py index 6bfbe99f..8b12c6aa 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -157,8 +157,9 @@ class TestWorker(RQTestCase): w = Worker([q]) # Put it on the queue with a timeout value - res = q.enqueue( - create_file_after_timeout, sentinel_file, 4, + res = q.enqueue_call( + func=create_file_after_timeout, + args=(sentinel_file, 4), timeout=1) try: