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

This commit is contained in:
Vincent Driessen 2012-07-23 11:50:32 +02:00
parent f6e67431d7
commit e6bb7de8c0
2 changed files with 13 additions and 9 deletions

View File

@ -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.

View File

@ -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: