From f6374f2dfa7401dfc52541d843efa6b13f17a66c Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 24 Jul 2012 08:33:28 +0200 Subject: [PATCH 1/3] Add new way of invoking .enqueue(), either implicitly or explicitly. --- rq/queue.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 9253aa1..3e73f71 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -138,15 +138,17 @@ class Queue(object): 'Functions from the __main__ module cannot be processed ' 'by workers.') - # 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) + # Detect explicit invocations, i.e. of the form: + # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30) + if 'args' in kwargs or 'kwargs' in kwargs: + assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs.' # noqa + options = kwargs + args = kwargs.pop('args', None) + kwargs = kwargs.pop('kwargs', None) + else: + options = {} + + return self.enqueue_call(func=f, args=args, kwargs=kwargs, **options) def enqueue_job(self, job, timeout=None, set_meta_data=True): """Enqueues a job for delayed execution. From d66939ff4af362d67043b1ee73c70786c84b66a7 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 24 Jul 2012 10:51:58 +0200 Subject: [PATCH 2/3] Don't use the (internal) .enqueue_call() in unit tests. --- tests/test_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_worker.py b/tests/test_worker.py index 8b12c6a..9ea338b 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -157,8 +157,8 @@ class TestWorker(RQTestCase): w = Worker([q]) # Put it on the queue with a timeout value - res = q.enqueue_call( - func=create_file_after_timeout, + res = q.enqueue( + create_file_after_timeout, args=(sentinel_file, 4), timeout=1) From abac4a5f41efe6c9faef7f8d1f28124c1fe94c3f Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 24 Jul 2012 11:13:06 +0200 Subject: [PATCH 3/3] Since we only have the timeout option, don't be too generic. --- rq/queue.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 3e73f71..7d78875 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=None, kwargs=None, **options): + def enqueue_call(self, func, args=None, kwargs=None, timeout=None): """Creates a job to represent the delayed function call and enqueues it. @@ -115,7 +115,7 @@ class Queue(object): and kwargs as explicit arguments. Any kwargs passed to this function contain options for RQ itself. """ - timeout = options.get('timeout', self._default_timeout) + timeout = timeout or self._default_timeout job = Job.create(func, args, kwargs, connection=self.connection) return self.enqueue_job(job, timeout=timeout) @@ -140,15 +140,15 @@ class Queue(object): # Detect explicit invocations, i.e. of the form: # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30) + timeout = None if 'args' in kwargs or 'kwargs' in kwargs: assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs.' # noqa - options = kwargs + timeout = kwargs.pop('timeout', None) args = kwargs.pop('args', None) kwargs = kwargs.pop('kwargs', None) - else: - options = {} - return self.enqueue_call(func=f, args=args, kwargs=kwargs, **options) + return self.enqueue_call(func=f, args=args, kwargs=kwargs, + timeout=timeout) def enqueue_job(self, job, timeout=None, set_meta_data=True): """Enqueues a job for delayed execution.