Skip to content

Commit

Permalink
Reflect new API in the RQ scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Mar 23, 2012
1 parent 2982486 commit a7c229d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bin/rqgenload
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -16,7 +16,7 @@ def main():

opts, args, parser = parse_args()

use_redis()
use_connection()

queues = ('default', 'high', 'low')

Expand Down
4 changes: 2 additions & 2 deletions bin/rqinfo
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions bin/rqworker
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions rq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from .version import VERSION


def use_redis(redis=None):
use_connection(redis)


__all__ = [
'use_connection', 'get_current_connection',
'push_connection', 'pop_connection', 'Connection',
Expand Down
5 changes: 4 additions & 1 deletion rq/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit a7c229d

Please sign in to comment.