Add support for passing configuration files to rqworker.

This fixes #123.
main
Vincent Driessen 12 years ago
parent e5eaedeef2
commit 1687633c07

@ -3,11 +3,13 @@ from rq import use_connection
def add_standard_arguments(parser): def add_standard_arguments(parser):
parser.add_argument('--host', '-H', default='localhost', parser.add_argument('--config', '-c', default=None,
help='Module containing RQ settings.')
parser.add_argument('--host', '-H', default=None,
help='The Redis hostname (default: localhost)') help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', type=int, default=6379, parser.add_argument('--port', '-p', default=None,
help='The Redis portnumber (default: 6379)') help='The Redis portnumber (default: 6379)')
parser.add_argument('--db', '-d', type=int, default=0, parser.add_argument('--db', '-d', type=int, default=None,
help='The Redis database (default: 0)') help='The Redis database (default: 0)')

@ -54,9 +54,27 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
def read_config_file(module):
"""Reads all UPPERCASE variables defined in the given module file."""
settings = __import__(module, [], [], [], -1)
return {k: v for k, v in settings.__dict__.items() if k.upper() == k}
def main(): def main():
args = parse_args() args = parse_args()
settings = {}
if args.config:
settings = read_config_file(args.config)
# Default arguments
if args.host is None:
args.host = settings.get('REDIS_HOST', 'localhost')
if args.port is None:
args.port = int(settings.get('REDIS_PORT', 6379))
if args.db is None:
args.db = settings.get('REDIS_DB', 0)
if args.path: if args.path:
sys.path = args.path.split(':') + sys.path sys.path = args.path.split(':') + sys.path

Loading…
Cancel
Save