diff --git a/redbeat/schedulers.py b/redbeat/schedulers.py index d7b277d..6da11d1 100644 --- a/redbeat/schedulers.py +++ b/redbeat/schedulers.py @@ -162,13 +162,15 @@ def __init__(self, app=None): self.key_prefix = self.either_or('redbeat_key_prefix', 'redbeat:') self.schedule_key = self.key_prefix + ':schedule' self.statics_key = self.key_prefix + ':statics' - self.lock_key = self.either_or('redbeat_lock_key', self.key_prefix + ':lock') - self.lock_timeout = self.either_or('redbeat_lock_timeout', None) self.redis_url = self.either_or('redbeat_redis_url', app.conf['BROKER_URL']) self.redis_use_ssl = self.either_or('redbeat_redis_use_ssl', app.conf['BROKER_USE_SSL']) self.redbeat_redis_options = self.either_or( 'redbeat_redis_options', app.conf['BROKER_TRANSPORT_OPTIONS'] ) + self.lock_key = self.either_or('redbeat_lock_key', self.key_prefix + ':lock') + if self.lock_key and not self.lock_key.startswith(self.key_prefix): + self.lock_key = self.key_prefix + self.lock_key + self.lock_timeout = self.either_or('redbeat_lock_timeout', None) @property def schedule(self): @@ -185,8 +187,14 @@ def either_or(self, name, default=None): 'configuration %s (use %s instead).' % (name, name.lower()), UserWarning, ) - return self.app.conf.first(name, name.upper()) or default + if self.is_key_in_conf(name): + return self.app.conf.first(name, name.upper()) + else: + return self.app.conf.first(name, name.upper()) or default + def is_key_in_conf(self, name): + if name.upper() in map(lambda k: k.upper(), self.app.conf.keys()): + return True class RedBeatSchedulerEntry(ScheduleEntry): _meta = None diff --git a/tests/test_config.py b/tests/test_config.py index a8ca545..fd57f94 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -29,6 +29,16 @@ def test_key_prefix_override(self): self.conf = RedBeatConfig(self.app) self.assertEqual(self.conf.key_prefix, 'test-prefix:') + def test_lock_key_might_be_set_to_none(self): + self.app.conf.redbeat_lock_key = None + self.conf = RedBeatConfig(self.app) + self.assertEqual(self.conf.lock_key, None) + + def test_lock_key_override(self): + self.app.conf.redbeat_lock_key = ":custom" + self.conf = RedBeatConfig(self.app) + self.assertEqual(self.conf.lock_key, 'redbeat::custom') + def test_schedule(self): schedule = {'foo': 'bar'} self.conf.schedule = schedule