Reflect new API in the RQ scripts.

main
Vincent Driessen 13 years ago
parent 2982486448
commit a7c229ddb1

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import optparse import optparse
from rq import use_redis, Queue, Worker from rq import use_connection, Queue, Worker
from rq import dummy from rq import dummy
@ -16,7 +16,7 @@ def main():
opts, args, parser = parse_args() opts, args, parser = parse_args()
use_redis() use_connection()
queues = ('default', 'high', 'low') queues = ('default', 'high', 'low')

@ -6,7 +6,7 @@ import time
import argparse import argparse
import redis import redis
from redis.exceptions import ConnectionError 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 from rq.utils import gettermsize, make_colorizer
red = make_colorizer('darkred') red = make_colorizer('darkred')
@ -146,7 +146,7 @@ def main():
# Setup connection to Redis # Setup connection to Redis
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_redis(redis_conn) use_connection(redis_conn)
try: try:
args.func(args) args.func(args)
except ConnectionError as e: except ConnectionError as e:

@ -4,7 +4,7 @@ import argparse
import logbook import logbook
import redis import redis
from logbook import handlers from logbook import handlers
from rq import use_redis, Queue, Worker from rq import use_connection, Queue, Worker
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
@ -64,7 +64,7 @@ def main():
# Setup connection to Redis # Setup connection to Redis
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_redis(redis_conn) use_connection(redis_conn)
try: try:
queues = map(Queue, args.queues) queues = map(Queue, args.queues)
w = Worker(queues, name=args.name) w = Worker(queues, name=args.name)

@ -7,10 +7,6 @@ from .worker import Worker
from .version import VERSION from .version import VERSION
def use_redis(redis=None):
use_connection(redis)
__all__ = [ __all__ = [
'use_connection', 'get_current_connection', 'use_connection', 'get_current_connection',
'push_connection', 'pop_connection', 'Connection', 'push_connection', 'pop_connection', 'Connection',

@ -60,13 +60,16 @@ def pop_connection():
return _connection_stack.pop() return _connection_stack.pop()
def use_connection(redis): def use_connection(redis=None):
"""Clears the stack and uses the given connection. Protects against mixed """Clears the stack and uses the given connection. Protects against mixed
use of use_connection() and stacked connection contexts. use of use_connection() and stacked connection contexts.
""" """
assert _connection_stack.depth() <= 1, \ assert _connection_stack.depth() <= 1, \
'You should not mix Connection contexts with use_connection().' 'You should not mix Connection contexts with use_connection().'
_connection_stack.empty() _connection_stack.empty()
if redis is None:
redis = Redis()
push_connection(redis) push_connection(redis)

Loading…
Cancel
Save