Skip to content

Commit

Permalink
Optionally configure connection as path to Unix socket (tbd: actual c…
Browse files Browse the repository at this point in the history
…onnection)
  • Loading branch information
jacob414 committed Mar 15, 2013
1 parent 5a5e14c commit 02288dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rq/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions rq/scripts/rqworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
21 changes: 20 additions & 1 deletion tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@
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')

0 comments on commit 02288dd

Please sign in to comment.