Skip to content

Commit efc9256

Browse files
authored
Merge pull request #206 from dealfinity/main
Hotfix/set lock key to none (#1)
2 parents 7462b2d + ee4a43c commit efc9256

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

redbeat/schedulers.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,15 @@ def __init__(self, app=None):
191191
self.key_prefix = self.either_or('redbeat_key_prefix', 'redbeat:')
192192
self.schedule_key = self.key_prefix + ':schedule'
193193
self.statics_key = self.key_prefix + ':statics'
194-
self.lock_key = self.either_or('redbeat_lock_key', self.key_prefix + ':lock')
195-
self.lock_timeout = self.either_or('redbeat_lock_timeout', None)
196194
self.redis_url = self.either_or('redbeat_redis_url', app.conf['BROKER_URL'])
197195
self.redis_use_ssl = self.either_or('redbeat_redis_use_ssl', app.conf['BROKER_USE_SSL'])
198196
self.redbeat_redis_options = self.either_or(
199197
'redbeat_redis_options', app.conf['BROKER_TRANSPORT_OPTIONS']
200198
)
199+
self.lock_key = self.either_or('redbeat_lock_key', self.key_prefix + ':lock')
200+
if self.lock_key and not self.lock_key.startswith(self.key_prefix):
201+
self.lock_key = self.key_prefix + self.lock_key
202+
self.lock_timeout = self.either_or('redbeat_lock_timeout', None)
201203

202204
@property
203205
def schedule(self):
@@ -214,8 +216,14 @@ def either_or(self, name, default=None):
214216
'configuration %s (use %s instead).' % (name, name.lower()),
215217
UserWarning,
216218
)
217-
return self.app.conf.first(name, name.upper()) or default
219+
if self.is_key_in_conf(name):
220+
return self.app.conf.first(name, name.upper())
221+
else:
222+
return self.app.conf.first(name, name.upper()) or default
218223

224+
def is_key_in_conf(self, name):
225+
if name.upper() in map(lambda k: k.upper(), self.app.conf.keys()):
226+
return True
219227

220228
class RedBeatSchedulerEntry(ScheduleEntry):
221229
_meta = None

tests/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ def test_key_prefix_override(self):
2929
self.conf = RedBeatConfig(self.app)
3030
self.assertEqual(self.conf.key_prefix, 'test-prefix:')
3131

32+
def test_lock_key_might_be_set_to_none(self):
33+
self.app.conf.redbeat_lock_key = None
34+
self.conf = RedBeatConfig(self.app)
35+
self.assertEqual(self.conf.lock_key, None)
36+
37+
def test_lock_key_override(self):
38+
self.app.conf.redbeat_lock_key = ":custom"
39+
self.conf = RedBeatConfig(self.app)
40+
self.assertEqual(self.conf.lock_key, 'redbeat::custom')
41+
3242
def test_schedule(self):
3343
schedule = {'foo': 'bar'}
3444
self.conf.schedule = schedule

0 commit comments

Comments
 (0)