|
|
@ -1,10 +1,12 @@
|
|
|
|
import times
|
|
|
|
import times
|
|
|
|
from .connections import resolve_connection
|
|
|
|
from .connections import resolve_connection
|
|
|
|
from .job import Job, Status
|
|
|
|
from .job import Job, Status
|
|
|
|
from .exceptions import (NoSuchJobError, UnpickleError,
|
|
|
|
from .exceptions import (DequeueTimeout, EnqueueError, InvalidJobOperationError,
|
|
|
|
InvalidJobOperationError, DequeueTimeout)
|
|
|
|
NoSuchJobError, UnpickleError)
|
|
|
|
from .compat import total_ordering
|
|
|
|
from .compat import total_ordering
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from redis import WatchError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_failed_queue(connection=None):
|
|
|
|
def get_failed_queue(connection=None):
|
|
|
|
"""Returns a handle to the special failed queue."""
|
|
|
|
"""Returns a handle to the special failed queue."""
|
|
|
@ -127,12 +129,23 @@ class Queue(object):
|
|
|
|
job = Job.create(func, args, kwargs, connection=self.connection,
|
|
|
|
job = Job.create(func, args, kwargs, connection=self.connection,
|
|
|
|
result_ttl=result_ttl, status=Status.QUEUED,
|
|
|
|
result_ttl=result_ttl, status=Status.QUEUED,
|
|
|
|
parent=after)
|
|
|
|
parent=after)
|
|
|
|
# If job depends on another job to finish, register itself on it's
|
|
|
|
|
|
|
|
|
|
|
|
# If job depends on an unfinished job, register itself on it's
|
|
|
|
# parent's waitlist instead of enqueueing it
|
|
|
|
# parent's waitlist instead of enqueueing it
|
|
|
|
if after is not None:
|
|
|
|
if after is not None:
|
|
|
|
|
|
|
|
with self.connection.pipeline() as pipe:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
pipe.watch(after.key)
|
|
|
|
|
|
|
|
if after.status != Status.FINISHED:
|
|
|
|
job.register_dependency()
|
|
|
|
job.register_dependency()
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
return job
|
|
|
|
return job
|
|
|
|
|
|
|
|
except WatchError:
|
|
|
|
|
|
|
|
raise EnqueueError(
|
|
|
|
|
|
|
|
'Parent job (%s) modified during enqueue process. ' +
|
|
|
|
|
|
|
|
'Bailing out to avoid race conditions' % after.id
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return self.enqueue_job(job, timeout=timeout)
|
|
|
|
return self.enqueue_job(job, timeout=timeout)
|
|
|
|
|
|
|
|
|
|
|
|
def enqueue(self, f, *args, **kwargs):
|
|
|
|
def enqueue(self, f, *args, **kwargs):
|
|
|
|