From 8581cd6463db0faf5f59db73f72cf89a76e9912f Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 3 Sep 2012 08:40:07 +0200 Subject: [PATCH] Don't allow jobs without Redis connection. And other connection-related fixes. --- rq/job.py | 11 +++++------ rq/queue.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rq/job.py b/rq/job.py index a8c7937..0b88cd8 100644 --- a/rq/job.py +++ b/rq/job.py @@ -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 diff --git a/rq/queue.py b/rq/queue.py index 6dca8e1..7dd90d2 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -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)