|
|
@ -75,11 +75,10 @@ def get_current_job(connection=None, job_class=None):
|
|
|
|
"""Returns the Job instance that is currently being executed. If this
|
|
|
|
"""Returns the Job instance that is currently being executed. If this
|
|
|
|
function is invoked from outside a job context, None is returned.
|
|
|
|
function is invoked from outside a job context, None is returned.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
job_class = job_class or Job
|
|
|
|
if job_class:
|
|
|
|
job_id = _job_stack.top
|
|
|
|
warnings.warn("job_class argument for get_current_job is deprecated.",
|
|
|
|
if job_id is None:
|
|
|
|
DeprecationWarning)
|
|
|
|
return None
|
|
|
|
return _job_stack.top
|
|
|
|
return job_class.fetch(job_id, connection=connection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Job(object):
|
|
|
|
class Job(object):
|
|
|
@ -553,11 +552,11 @@ class Job(object):
|
|
|
|
def perform(self): # noqa
|
|
|
|
def perform(self): # noqa
|
|
|
|
"""Invokes the job function with the job arguments."""
|
|
|
|
"""Invokes the job function with the job arguments."""
|
|
|
|
self.connection.persist(self.key)
|
|
|
|
self.connection.persist(self.key)
|
|
|
|
_job_stack.push(self.id)
|
|
|
|
_job_stack.push(self)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self._result = self._execute()
|
|
|
|
self._result = self._execute()
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
assert self.id == _job_stack.pop()
|
|
|
|
assert self is _job_stack.pop()
|
|
|
|
return self._result
|
|
|
|
return self._result
|
|
|
|
|
|
|
|
|
|
|
|
def _execute(self):
|
|
|
|
def _execute(self):
|
|
|
@ -607,7 +606,7 @@ class Job(object):
|
|
|
|
self.delete(pipeline=pipeline, remove_from_queue=remove_from_queue)
|
|
|
|
self.delete(pipeline=pipeline, remove_from_queue=remove_from_queue)
|
|
|
|
elif not ttl:
|
|
|
|
elif not ttl:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
if ttl > 0:
|
|
|
|
if ttl > 0:
|
|
|
|
connection.expire(self.key, ttl)
|
|
|
|
connection.expire(self.key, ttl)
|
|
|
|