Reflect new API in the RQ scripts.

This commit is contained in:
Vincent Driessen 2012-03-23 15:15:29 +01:00
parent 2982486448
commit a7c229ddb1
5 changed files with 10 additions and 11 deletions

View File

@ -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')

View File

@ -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:

View File

@ -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)

View File

@ -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',

View File

@ -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)