Don't allow jobs without Redis connection.

And other connection-related fixes.
main
Vincent Driessen 13 years ago
parent 86dc1e3533
commit 8581cd6463

@ -4,7 +4,8 @@ import times
from collections import namedtuple
from uuid import uuid4
from cPickle import loads, dumps, UnpicklingError
from .connections import get_current_connection
from .local import LocalStack
from .connections import resolve_connection
from .exceptions import UnpickleError, NoSuchJobError
@ -135,9 +136,9 @@ class Job(object):
return self._kwargs
@classmethod
def exists(cls, job_id):
def exists(cls, job_id, connection=None):
"""Returns whether a job hash exists for the given job ID."""
conn = get_current_connection()
conn = resolve_connection(connection)
return conn.exists(cls.key_for(job_id))
@classmethod
@ -150,9 +151,7 @@ class Job(object):
return job
def __init__(self, id=None, connection=None):
if connection is None:
connection = get_current_connection()
self.connection = connection
self.connection = resolve_connection(connection)
self._id = id
self.created_at = times.now()
self._func_name = None

@ -98,7 +98,7 @@ class Queue(object):
job_id = self.connection.lpop(COMPACT_QUEUE)
if job_id is None:
break
if Job.exists(job_id):
if Job.exists(job_id, self.connection):
self.connection.rpush(self.key, job_id)

Loading…
Cancel
Save