Get rid of the ambiguity when passing the timeout argument to .enqueue() calls.

main
Vincent Driessen 13 years ago
parent f6e67431d7
commit e6bb7de8c0

@ -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, kwargs, **options): def enqueue_call(self, func, args=None, kwargs=None, **options):
"""Creates a job to represent the delayed function call and enqueues """Creates a job to represent the delayed function call and enqueues
it. it.
@ -138,12 +138,15 @@ class Queue(object):
'Functions from the __main__ module cannot be processed ' 'Functions from the __main__ module cannot be processed '
'by workers.') 'by workers.')
options = {} # Warn about the timeout flag that has been removed
try: if 'timeout' in kwargs:
options['timeout'] = kwargs.pop('timeout') import warnings
except KeyError: warnings.warn('The use of the timeout kwarg is not supported '
pass 'anymore. If you meant to pass this argument to RQ '
return self.enqueue_call(func=f, args=args, kwargs=kwargs, **options) '(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): 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,9 @@ 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( res = q.enqueue_call(
create_file_after_timeout, sentinel_file, 4, func=create_file_after_timeout,
args=(sentinel_file, 4),
timeout=1) timeout=1)
try: try:

Loading…
Cancel
Save