Skip to content

Commit

Permalink
[#3994] Pass a timeout through to the rq.Job object.
Browse files Browse the repository at this point in the history
Pass the job timeout kwarg through to the `rq.queue.enqueue_call` method.

Get the default job timeout from the ckan config.
  • Loading branch information
scottdillon committed Dec 21, 2018
1 parent 8f0cb74 commit 9fcc0db
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ckan/lib/jobs.py
Expand Up @@ -36,6 +36,7 @@
log = logging.getLogger(__name__)

DEFAULT_QUEUE_NAME = u'default'
DEFAULT_JOB_TIMEOUT = config[u'rq.bg_job_timeout']

# RQ job queues. Do not use this directly, use ``get_queue`` instead.
_queues = {}
Expand Down Expand Up @@ -123,7 +124,8 @@ def get_queue(name=DEFAULT_QUEUE_NAME):
return queue


def enqueue(fn, args=None, kwargs=None, title=None, queue=DEFAULT_QUEUE_NAME):
def enqueue(fn, args=None, kwargs=None, title=None, queue=DEFAULT_QUEUE_NAME,
timeout=DEFAULT_JOB_TIMEOUT):
u'''
Enqueue a job to be run in the background.
Expand All @@ -141,14 +143,18 @@ def enqueue(fn, args=None, kwargs=None, title=None, queue=DEFAULT_QUEUE_NAME):
:param string queue: Name of the queue. If not given then the
default queue is used.
:param integer timeout: The timeout, in seconds, to be passed
to the background job via rq.
:returns: The enqueued job.
:rtype: ``rq.job.Job``
'''
if args is None:
args = []
if kwargs is None:
kwargs = {}
job = get_queue(queue).enqueue_call(func=fn, args=args, kwargs=kwargs)
job = get_queue(queue).enqueue_call(func=fn, args=args, kwargs=kwargs,
timeout=None)
job.meta[u'title'] = title
job.save()
msg = u'Added background job {}'.format(job.id)
Expand Down

0 comments on commit 9fcc0db

Please sign in to comment.