Merge pull request #198 from johannth/scripts-respect-url

Made rqworker and rqinfo respect db parameters from --url
main
Vincent Driessen 12 years ago
commit 0f804e07ae

@ -7,7 +7,8 @@ def add_standard_arguments(parser):
parser.add_argument('--config', '-c', default=None, parser.add_argument('--config', '-c', default=None,
help='Module containing RQ settings.') help='Module containing RQ settings.')
parser.add_argument('--url', '-u', default=None, 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, parser.add_argument('--host', '-H', default=None,
help='The Redis hostname (default: localhost)') help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', default=None, parser.add_argument('--port', '-p', default=None,
@ -47,13 +48,10 @@ def setup_default_arguments(args, settings):
if args.password is None: if args.password is None:
args.password = settings.get('REDIS_PASSWORD', None) args.password = settings.get('REDIS_PASSWORD', None)
if not args.queues:
args.queues = settings.get('QUEUES', ['default'])
def setup_redis(args): def setup_redis(args):
if args.url is not None: 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: else:
redis_conn = redis.StrictRedis(host=args.host, port=args.port, db=args.db, redis_conn = redis.StrictRedis(host=args.host, port=args.port, db=args.db,
password=args.password, unix_socket_path=args.socket) password=args.password, unix_socket_path=args.socket)

@ -21,6 +21,7 @@ def pad(s, pad_to_length):
"""Pads the given string to the given length.""" """Pads the given string to the given length."""
return ('%-' + '%ds' % pad_to_length) % (s,) return ('%-' + '%ds' % pad_to_length) % (s,)
def get_scale(x): def get_scale(x):
"""Finds the lowest scale where x <= scale.""" """Finds the lowest scale where x <= scale."""
scales = [20, 50, 100, 200, 400, 600, 800, 1000] scales = [20, 50, 100, 200, 400, 600, 800, 1000]
@ -29,6 +30,7 @@ def get_scale(x):
return scale return scale
return x return x
def state_symbol(state): def state_symbol(state):
symbols = { symbols = {
'busy': red('busy'), 'busy': red('busy'),
@ -186,4 +188,3 @@ def main():
except KeyboardInterrupt: except KeyboardInterrupt:
print print
sys.exit(0) sys.exit(0)

@ -32,6 +32,19 @@ def parse_args():
return parser.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(): def main():
args = parse_args() args = parse_args()
@ -44,21 +57,15 @@ def main():
setup_default_arguments(args, settings) 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: if args.sentry_dsn is None:
args.sentry_dsn = settings.get('SENTRY_DSN', args.sentry_dsn = settings.get('SENTRY_DSN',
os.environ.get('SENTRY_DSN', None)) os.environ.get('SENTRY_DSN', None))
if args.verbose and args.quiet: setup_loghandlers_from_args(args)
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_redis(args) setup_redis(args)
cleanup_ghosts() cleanup_ghosts()

Loading…
Cancel
Save