Merge branch 'new-enqueue' into selwin-decorator

main
Vincent Driessen 13 years ago
commit ea19bdc910

@ -107,7 +107,7 @@ class Queue(object):
"""Pushes a job ID on the corresponding Redis queue.""" """Pushes a job ID on the corresponding Redis queue."""
self.connection.rpush(self.key, job_id) 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 """Creates a job to represent the delayed function call and enqueues
it. it.
@ -115,7 +115,7 @@ class Queue(object):
and kwargs as explicit arguments. Any kwargs passed to this function and kwargs as explicit arguments. Any kwargs passed to this function
contain options for RQ itself. 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) job = Job.create(func, args, kwargs, connection=self.connection)
return self.enqueue_job(job, timeout=timeout) return self.enqueue_job(job, timeout=timeout)
@ -138,15 +138,17 @@ class Queue(object):
'Functions from the __main__ module cannot be processed ' 'Functions from the __main__ module cannot be processed '
'by workers.') 'by workers.')
# Warn about the timeout flag that has been removed # Detect explicit invocations, i.e. of the form:
if 'timeout' in kwargs: # q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30)
import warnings timeout = None
warnings.warn('The use of the timeout kwarg is not supported ' if 'args' in kwargs or 'kwargs' in kwargs:
'anymore. If you meant to pass this argument to RQ ' assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs.' # noqa
'(rather than to %r), use the `.enqueue_call()` ' timeout = kwargs.pop('timeout', None)
'method instead.' % f, DeprecationWarning) args = kwargs.pop('args', None)
kwargs = kwargs.pop('kwargs', None)
return self.enqueue_call(func=f, args=args, kwargs=kwargs)
return self.enqueue_call(func=f, args=args, kwargs=kwargs,
timeout=timeout)
def enqueue_job(self, job, timeout=None, set_meta_data=True): def enqueue_job(self, job, timeout=None, set_meta_data=True):
"""Enqueues a job for delayed execution. """Enqueues a job for delayed execution.

@ -157,8 +157,8 @@ class TestWorker(RQTestCase):
w = Worker([q]) w = Worker([q])
# Put it on the queue with a timeout value # Put it on the queue with a timeout value
res = q.enqueue_call( res = q.enqueue(
func=create_file_after_timeout, create_file_after_timeout,
args=(sentinel_file, 4), args=(sentinel_file, 4),
timeout=1) timeout=1)

Loading…
Cancel
Save