Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/set lock key to none (#1) #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions redbeat/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down