Skip to content

Commit

Permalink
Merge pull request rq#198 from johannth/scripts-respect-url
Browse files Browse the repository at this point in the history
Made rqworker and rqinfo respect db parameters from --url
  • Loading branch information
nvie committed Apr 19, 2013
2 parents bf802a1 + 7660fbd commit 0f804e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
8 changes: 3 additions & 5 deletions rq/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def add_standard_arguments(parser):
parser.add_argument('--config', '-c', default=None,
help='Module containing RQ settings.')
parser.add_argument('--url', '-u', default=None,
help='URL describing Redis connection details')
help='URL describing Redis connection details. '
'Overrides other connection arguments if supplied.')
parser.add_argument('--host', '-H', default=None,
help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', default=None,
Expand Down Expand Up @@ -47,13 +48,10 @@ def setup_default_arguments(args, settings):
if args.password is None:
args.password = settings.get('REDIS_PASSWORD', None)

if not args.queues:
args.queues = settings.get('QUEUES', ['default'])


def setup_redis(args):
if args.url is not None:
redis_conn = redis.StrictRedis.from_url(args.url, db=args.db)
redis_conn = redis.StrictRedis.from_url(args.url)
else:
redis_conn = redis.StrictRedis(host=args.host, port=args.port, db=args.db,
password=args.password, unix_socket_path=args.socket)
Expand Down
3 changes: 2 additions & 1 deletion rq/scripts/rqinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def pad(s, pad_to_length):
"""Pads the given string to the given length."""
return ('%-' + '%ds' % pad_to_length) % (s,)


def get_scale(x):
"""Finds the lowest scale where x <= scale."""
scales = [20, 50, 100, 200, 400, 600, 800, 1000]
Expand All @@ -29,6 +30,7 @@ def get_scale(x):
return scale
return x


def state_symbol(state):
symbols = {
'busy': red('busy'),
Expand Down Expand Up @@ -186,4 +188,3 @@ def main():
except KeyboardInterrupt:
print
sys.exit(0)

29 changes: 18 additions & 11 deletions rq/scripts/rqworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ def parse_args():
return parser.parse_args()


def setup_loghandlers_from_args(args):
if args.verbose and args.quiet:
raise RuntimeError("Flags --verbose and --quiet are mutually exclusive.")

if args.verbose:
level = 'DEBUG'
elif args.quiet:
level = 'WARNING'
else:
level = 'INFO'
setup_loghandlers(level)


def main():
args = parse_args()

Expand All @@ -44,21 +57,15 @@ def main():

setup_default_arguments(args, settings)

# Other default arguments
# Worker specific default arguments
if not args.queues:
args.queues = settings.get('QUEUES', ['default'])

if args.sentry_dsn is None:
args.sentry_dsn = settings.get('SENTRY_DSN',
os.environ.get('SENTRY_DSN', None))

if args.verbose and args.quiet:
raise RuntimeError("Flags --verbose and --quiet are mutually exclusive.")

if args.verbose:
level = 'DEBUG'
elif args.quiet:
level = 'WARNING'
else:
level = 'INFO'
setup_loghandlers(level)
setup_loghandlers_from_args(args)
setup_redis(args)

cleanup_ghosts()
Expand Down

0 comments on commit 0f804e0

Please sign in to comment.