|
|
@ -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):
|
|
|
@ -479,18 +478,18 @@ class Job(object):
|
|
|
|
|
|
|
|
|
|
|
|
def save(self, pipeline=None, include_meta=True):
|
|
|
|
def save(self, pipeline=None, include_meta=True):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Persists the current job instance to its corresponding Redis key.
|
|
|
|
Dumps the current job instance to its corresponding Redis key.
|
|
|
|
|
|
|
|
|
|
|
|
Exclude persisting the `meta` dictionary by setting
|
|
|
|
Exclude saving the `meta` dictionary by setting
|
|
|
|
`include_meta=False`. This is useful to prevent clobbering
|
|
|
|
`include_meta=False`. This is useful to prevent clobbering
|
|
|
|
user metadata without an expensive `refresh()` call first.
|
|
|
|
user metadata without an expensive `refresh()` call first.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Redis key persistence may be altered by `cleanup()` method.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
key = self.key
|
|
|
|
key = self.key
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
connection = pipeline if pipeline is not None else self.connection
|
|
|
|
|
|
|
|
|
|
|
|
connection.hmset(key, self.to_dict(include_meta=include_meta))
|
|
|
|
connection.hmset(key, self.to_dict(include_meta=include_meta))
|
|
|
|
self.cleanup(self.ttl, pipeline=connection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_meta(self):
|
|
|
|
def save_meta(self):
|
|
|
|
"""Stores job meta from the job instance to the corresponding Redis key."""
|
|
|
|
"""Stores job meta from the job instance to the corresponding Redis key."""
|
|
|
@ -548,17 +547,15 @@ class Job(object):
|
|
|
|
connection.delete(self.key)
|
|
|
|
connection.delete(self.key)
|
|
|
|
connection.delete(self.dependents_key)
|
|
|
|
connection.delete(self.dependents_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Job execution
|
|
|
|
# Job execution
|
|
|
|
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)
|
|
|
|
self.ttl = -1
|
|
|
|
_job_stack.push(self)
|
|
|
|
_job_stack.push(self.id)
|
|
|
|
|
|
|
|
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):
|
|
|
|