diff --git a/CHANGES.md b/CHANGES.md index e56c71f..d8b6da3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,9 +1,18 @@ -### 0.3.2 +### 0.3.3 (not released yet) - Access the current job from within the job function (`rq.get_current_job()`). +### 0.3.2 +(September 3rd, 2012) + +- Fixes broken `rqinfo` command. + +- Improve compatibility with Python < 2.7. + + + ### 0.3.1 (August 30th, 2012) diff --git a/rq/job.py b/rq/job.py index 6faefa9..f508e02 100644 --- a/rq/job.py +++ b/rq/job.py @@ -5,7 +5,7 @@ from collections import namedtuple from uuid import uuid4 from cPickle import loads, dumps, UnpicklingError from .local import LocalStack -from .connections import get_current_connection +from .connections import resolve_connection from .exceptions import UnpickleError, NoSuchJobError @@ -146,9 +146,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 @@ -161,9 +161,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) diff --git a/rq/scripts/__init__.py b/rq/scripts/__init__.py index e615f8d..a675385 100644 --- a/rq/scripts/__init__.py +++ b/rq/scripts/__init__.py @@ -13,6 +13,26 @@ def add_standard_arguments(parser): help='The Redis database (default: 0)') +def read_config_file(module): + """Reads all UPPERCASE variables defined in the given module file.""" + settings = __import__(module, [], [], [], -1) + return dict([(k, v) + for k, v in settings.__dict__.items() + if k.upper() == k]) + + +def setup_default_arguments(args, settings): + """ Sets up args from settings or defaults """ + if args.host is None: + args.host = settings.get('REDIS_HOST', 'localhost') + if args.port is None: + args.port = int(settings.get('REDIS_PORT', 6379)) + else: + args.port = int(args.port) + if args.db is None: + args.db = settings.get('REDIS_DB', 0) + + def setup_redis(args): redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) use_connection(redis_conn) diff --git a/rq/scripts/rqinfo.py b/rq/scripts/rqinfo.py index 0782cd3..6920783 100755 --- a/rq/scripts/rqinfo.py +++ b/rq/scripts/rqinfo.py @@ -9,6 +9,8 @@ from rq import Queue, Worker from rq.utils import gettermsize, make_colorizer from rq.scripts import add_standard_arguments from rq.scripts import setup_redis +from rq.scripts import read_config_file +from rq.scripts import setup_default_arguments red = make_colorizer('darkred') green = make_colorizer('darkgreen') @@ -162,6 +164,12 @@ def main(): if args.path: sys.path = args.path.split(':') + sys.path + settings = {} + if args.config: + settings = read_config_file(args.config) + + setup_default_arguments(args, settings) + setup_redis(args) try: if args.only_queues: diff --git a/rq/scripts/rqworker.py b/rq/scripts/rqworker.py index c870989..be38188 100755 --- a/rq/scripts/rqworker.py +++ b/rq/scripts/rqworker.py @@ -7,6 +7,8 @@ from rq import Queue, Worker from redis.exceptions import ConnectionError from rq.scripts import add_standard_arguments from rq.scripts import setup_redis +from rq.scripts import read_config_file +from rq.scripts import setup_default_arguments def format_colors(record, handler): @@ -53,12 +55,6 @@ def parse_args(): return parser.parse_args() -def read_config_file(module): - """Reads all UPPERCASE variables defined in the given module file.""" - settings = __import__(module, [], [], [], -1) - return {k: v for k, v in settings.__dict__.items() if k.upper() == k} - - def main(): args = parse_args() @@ -69,13 +65,9 @@ def main(): if args.config: settings = read_config_file(args.config) - # Default arguments - if args.host is None: - args.host = settings.get('REDIS_HOST', 'localhost') - if args.port is None: - args.port = int(settings.get('REDIS_PORT', 6379)) - if args.db is None: - args.db = settings.get('REDIS_DB', 0) + setup_default_arguments(args, settings) + + # Other default arguments if args.sentry_dsn is None: args.sentry_dsn = settings.get('SENTRY_DSN', None) diff --git a/rq/version.py b/rq/version.py index 64a0641..9cd79b5 100644 --- a/rq/version.py +++ b/rq/version.py @@ -1 +1 @@ -VERSION = '0.3.1' +VERSION = '0.3.2'