Merge branch 'master' into job-access-within-job

Conflicts:
	rq/job.py
main
Vincent Driessen 12 years ago
commit 4b66d7af41

@ -1,9 +1,18 @@
### 0.3.2 ### 0.3.3
(not released yet) (not released yet)
- Access the current job from within the job function (`rq.get_current_job()`). - 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 ### 0.3.1
(August 30th, 2012) (August 30th, 2012)

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

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

@ -13,6 +13,26 @@ def add_standard_arguments(parser):
help='The Redis database (default: 0)') 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): def setup_redis(args):
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db)
use_connection(redis_conn) use_connection(redis_conn)

@ -9,6 +9,8 @@ from rq import Queue, Worker
from rq.utils import gettermsize, make_colorizer from rq.utils import gettermsize, make_colorizer
from rq.scripts import add_standard_arguments from rq.scripts import add_standard_arguments
from rq.scripts import setup_redis from rq.scripts import setup_redis
from rq.scripts import read_config_file
from rq.scripts import setup_default_arguments
red = make_colorizer('darkred') red = make_colorizer('darkred')
green = make_colorizer('darkgreen') green = make_colorizer('darkgreen')
@ -162,6 +164,12 @@ def main():
if args.path: if args.path:
sys.path = args.path.split(':') + sys.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) setup_redis(args)
try: try:
if args.only_queues: if args.only_queues:

@ -7,6 +7,8 @@ from rq import Queue, Worker
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq.scripts import add_standard_arguments from rq.scripts import add_standard_arguments
from rq.scripts import setup_redis 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): def format_colors(record, handler):
@ -53,12 +55,6 @@ def parse_args():
return parser.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(): def main():
args = parse_args() args = parse_args()
@ -69,13 +65,9 @@ def main():
if args.config: if args.config:
settings = read_config_file(args.config) settings = read_config_file(args.config)
# Default arguments setup_default_arguments(args, settings)
if args.host is None:
args.host = settings.get('REDIS_HOST', 'localhost') # Other default arguments
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)
if args.sentry_dsn is None: if args.sentry_dsn is None:
args.sentry_dsn = settings.get('SENTRY_DSN', None) args.sentry_dsn = settings.get('SENTRY_DSN', None)

@ -1 +1 @@
VERSION = '0.3.1' VERSION = '0.3.2'

Loading…
Cancel
Save