diff --git a/rq/scripts/__init__.py b/rq/scripts/__init__.py index 119f4f6..071d9fe 100644 --- a/rq/scripts/__init__.py +++ b/rq/scripts/__init__.py @@ -36,6 +36,10 @@ def setup_default_arguments(args, settings): else: args.port = int(args.port) + socket = settings.get('REDIS_SOCKET', False) + if args.socket is None and socket: + args.socket = socket + if args.db is None: args.db = settings.get('REDIS_DB', 0) diff --git a/rq/scripts/rqworker.py b/rq/scripts/rqworker.py index 2e00494..ccb5db7 100755 --- a/rq/scripts/rqworker.py +++ b/rq/scripts/rqworker.py @@ -27,6 +27,7 @@ def parse_args(): parser.add_argument('--quiet', '-q', action='store_true', default=False, help='Show less output') parser.add_argument('--sentry-dsn', action='store', default=None, metavar='URL', help='Report exceptions to this Sentry DSN') parser.add_argument('queues', nargs='*', help='The queues to listen on (default: \'default\')') + parser.add_argument('--socket', '-s', default=None, help='Use Unix socket to connect') return parser.parse_args() diff --git a/tests/test_scripts.py b/tests/test_scripts.py index ae661c7..027abe6 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -3,11 +3,30 @@ if is_python_version((2, 7), (3, 2)): from unittest import TestCase else: from unittest2 import TestCase # noqa -from rq.scripts import read_config_file +from rq.scripts import read_config_file, setup_redis, add_standard_arguments, setup_default_arguments +class uFaking(object): + def __init__(self, *faking): + for attr in faking: + setattr(self, attr, None) + +def conf_pair(**faked_settings): + return (faked_settings, + uFaking('host', 'port', 'socket', 'db', 'queues', 'password')) class TestScripts(TestCase): def test_config_file(self): settings = read_config_file("tests.dummy_settings") self.assertIn("REDIS_HOST", settings) self.assertEqual(settings['REDIS_HOST'], "testhost.example.com") + + def test_socket_from_module(self): + settings, args = conf_pair(REDIS_SOCKET='dummy') + setup_default_arguments(args, settings) + self.assertEqual(args.socket, 'dummy') + + def test_socket_from_args(self): + settings, args = conf_pair(REDIS_SOCKET='sock-read-from-config') + args.socket = 'sock-from-arg' + setup_default_arguments(args, settings) + self.assertEqual(args.socket, 'sock-from-arg')