Merge pull request #788 from friedcell/master

Better support for async job payloads
main
Selwin Ong 8 years ago committed by GitHub
commit 5660f925ae

@ -552,11 +552,14 @@ class Job(object):
self.ttl = -1 self.ttl = -1
_job_stack.push(self.id) _job_stack.push(self.id)
try: try:
self._result = self.func(*self.args, **self.kwargs) self._result = self._execute()
finally: finally:
assert self.id == _job_stack.pop() assert self.id == _job_stack.pop()
return self._result return self._result
def _execute(self):
return self.func(*self.args, **self.kwargs)
def get_ttl(self, default_ttl=None): def get_ttl(self, default_ttl=None):
"""Returns ttl for a job that determines how long a job will be """Returns ttl for a job that determines how long a job will be
persisted. In the future, this method will also be responsible persisted. In the future, this method will also be responsible

@ -232,11 +232,15 @@ class Queue(object):
job = self.enqueue_job(job, at_front=at_front) job = self.enqueue_job(job, at_front=at_front)
if not self._async: if not self._async:
job = self.run_job(job)
return job
def run_job(self, job):
job.perform() job.perform()
job.set_status(JobStatus.FINISHED) job.set_status(JobStatus.FINISHED)
job.save(include_meta=False) job.save(include_meta=False)
job.cleanup(DEFAULT_RESULT_TTL) job.cleanup(DEFAULT_RESULT_TTL)
return job return job
def enqueue(self, f, *args, **kwargs): def enqueue(self, f, *args, **kwargs):

Loading…
Cancel
Save