From a7c229ddb143ed592d34048498011cbb382d76b5 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Fri, 23 Mar 2012 15:15:29 +0100 Subject: [PATCH] Reflect new API in the RQ scripts. --- bin/rqgenload | 4 ++-- bin/rqinfo | 4 ++-- bin/rqworker | 4 ++-- rq/__init__.py | 4 ---- rq/connections.py | 5 ++++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bin/rqgenload b/bin/rqgenload index 8aaf46e0..a6e4cfd0 100755 --- a/bin/rqgenload +++ b/bin/rqgenload @@ -1,6 +1,6 @@ #!/usr/bin/env python import optparse -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from rq import dummy @@ -16,7 +16,7 @@ def main(): opts, args, parser = parse_args() - use_redis() + use_connection() queues = ('default', 'high', 'low') diff --git a/bin/rqinfo b/bin/rqinfo index 8c5f3f10..06e8192e 100755 --- a/bin/rqinfo +++ b/bin/rqinfo @@ -6,7 +6,7 @@ import time import argparse import redis from redis.exceptions import ConnectionError -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from rq.utils import gettermsize, make_colorizer red = make_colorizer('darkred') @@ -146,7 +146,7 @@ def main(): # Setup connection to Redis redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) - use_redis(redis_conn) + use_connection(redis_conn) try: args.func(args) except ConnectionError as e: diff --git a/bin/rqworker b/bin/rqworker index 3d390fd5..e6a72e24 100755 --- a/bin/rqworker +++ b/bin/rqworker @@ -4,7 +4,7 @@ import argparse import logbook import redis from logbook import handlers -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from redis.exceptions import ConnectionError @@ -64,7 +64,7 @@ def main(): # Setup connection to Redis redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) - use_redis(redis_conn) + use_connection(redis_conn) try: queues = map(Queue, args.queues) w = Worker(queues, name=args.name) diff --git a/rq/__init__.py b/rq/__init__.py index f70e950b..40ea2266 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -7,10 +7,6 @@ from .worker import Worker from .version import VERSION -def use_redis(redis=None): - use_connection(redis) - - __all__ = [ 'use_connection', 'get_current_connection', 'push_connection', 'pop_connection', 'Connection', diff --git a/rq/connections.py b/rq/connections.py index 4087d410..c714a352 100644 --- a/rq/connections.py +++ b/rq/connections.py @@ -60,13 +60,16 @@ def pop_connection(): return _connection_stack.pop() -def use_connection(redis): +def use_connection(redis=None): """Clears the stack and uses the given connection. Protects against mixed use of use_connection() and stacked connection contexts. """ assert _connection_stack.depth() <= 1, \ 'You should not mix Connection contexts with use_connection().' _connection_stack.empty() + + if redis is None: + redis = Redis() push_connection(redis)