|
|
@ -260,24 +260,26 @@ class Queue(object):
|
|
|
|
description=description, depends_on=depends_on,
|
|
|
|
description=description, depends_on=depends_on,
|
|
|
|
job_id=job_id, at_front=at_front)
|
|
|
|
job_id=job_id, at_front=at_front)
|
|
|
|
|
|
|
|
|
|
|
|
def enqueue_job(self, job, at_front=False):
|
|
|
|
def enqueue_job(self, job, pipeline=None, at_front=False):
|
|
|
|
"""Enqueues a job for delayed execution.
|
|
|
|
"""Enqueues a job for delayed execution.
|
|
|
|
|
|
|
|
|
|
|
|
If Queue is instantiated with async=False, job is executed immediately.
|
|
|
|
If Queue is instantiated with async=False, job is executed immediately.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
with self.connection._pipeline() as pipeline:
|
|
|
|
pipe = pipeline if pipeline is not None else self.connection._pipeline()
|
|
|
|
|
|
|
|
|
|
|
|
# Add Queue key set
|
|
|
|
# Add Queue key set
|
|
|
|
self.connection.sadd(self.redis_queues_keys, self.key)
|
|
|
|
pipe.sadd(self.redis_queues_keys, self.key)
|
|
|
|
job.set_status(JobStatus.QUEUED, pipeline=pipeline)
|
|
|
|
job.set_status(JobStatus.QUEUED, pipeline=pipe)
|
|
|
|
|
|
|
|
|
|
|
|
job.origin = self.name
|
|
|
|
job.origin = self.name
|
|
|
|
job.enqueued_at = utcnow()
|
|
|
|
job.enqueued_at = utcnow()
|
|
|
|
|
|
|
|
|
|
|
|
if job.timeout is None:
|
|
|
|
if job.timeout is None:
|
|
|
|
job.timeout = self.DEFAULT_TIMEOUT
|
|
|
|
job.timeout = self.DEFAULT_TIMEOUT
|
|
|
|
job.save(pipeline=pipeline)
|
|
|
|
job.save(pipeline=pipe)
|
|
|
|
|
|
|
|
|
|
|
|
pipeline.execute()
|
|
|
|
if pipeline is None:
|
|
|
|
|
|
|
|
pipe.execute()
|
|
|
|
|
|
|
|
|
|
|
|
if self._async:
|
|
|
|
if self._async:
|
|
|
|
self.push_job_id(job.id, at_front=at_front)
|
|
|
|
self.push_job_id(job.id, at_front=at_front)
|
|
|
@ -289,15 +291,20 @@ class Queue(object):
|
|
|
|
# TODO: can probably be pipelined
|
|
|
|
# TODO: can probably be pipelined
|
|
|
|
from .registry import DeferredJobRegistry
|
|
|
|
from .registry import DeferredJobRegistry
|
|
|
|
|
|
|
|
|
|
|
|
registry = DeferredJobRegistry(self.name, self.connection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
job_id = as_text(self.connection.spop(job.dependents_key))
|
|
|
|
job_id = as_text(self.connection.spop(job.dependents_key))
|
|
|
|
if job_id is None:
|
|
|
|
if job_id is None:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
dependent = self.job_class.fetch(job_id, connection=self.connection)
|
|
|
|
dependent = self.job_class.fetch(job_id, connection=self.connection)
|
|
|
|
registry.remove(dependent)
|
|
|
|
registry = DeferredJobRegistry(dependent.origin, self.connection)
|
|
|
|
self.enqueue_job(dependent)
|
|
|
|
with self.connection._pipeline() as pipeline:
|
|
|
|
|
|
|
|
registry.remove(dependent, pipeline=pipeline)
|
|
|
|
|
|
|
|
if dependent.origin == self.name:
|
|
|
|
|
|
|
|
self.enqueue_job(dependent, pipeline=pipeline)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
queue = Queue(name=dependent.origin, connection=self.connection)
|
|
|
|
|
|
|
|
queue.enqueue_job(dependent, pipeline=pipeline)
|
|
|
|
|
|
|
|
pipeline.execute()
|
|
|
|
|
|
|
|
|
|
|
|
def pop_job_id(self):
|
|
|
|
def pop_job_id(self):
|
|
|
|
"""Pops a given job ID from this Redis queue."""
|
|
|
|
"""Pops a given job ID from this Redis queue."""
|
|
|
|