Skip to content

Commit

Permalink
scheduler: use saved enabled state of tasks
Browse files Browse the repository at this point in the history
* Uses enabled state of task already saved in REDIS. Closes rero#1033.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed Jun 15, 2020
1 parent b7752a1 commit 2974aeb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rero_ils/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def merge_inplace(self, tasks):
"""
for name in tasks:
enabled = tasks[name].pop('enabled', True)
self.rdb[self.enabled_name(name)] = int(enabled)
if not self.rdb.get(self.enabled_name(name)):
self.rdb[self.enabled_name(name)] = int(enabled)
super(RedisScheduler, self).merge_inplace(tasks)

def setup_schedule(self):
Expand Down Expand Up @@ -166,6 +167,15 @@ def remove(self, name):
del self.rdb[enabled_name]
return super(RedisScheduler, self).remove(task_key=name)

def reset(self):
"""Reset all scheduled tasks."""
for entry in self.rdb.zrange(self.key, 0, -1):
entry = jsonpickle.decode(entry)
enabled_name = self.enabled_name(entry.name)
if self.rdb.get(enabled_name):
del self.rdb[enabled_name]
self._remove_db()

def add_entry(self, entry, enable=True):
"""Add an entry.
Expand Down Expand Up @@ -295,7 +305,7 @@ def init(reset, verbose):
"""
if reset:
click.secho('Reset REDIS scheduler!', fg='red', bold=True)
current_scheduler._remove_db()
current_scheduler.reset()
else:
click.secho('Initalize REDIS scheduler!', fg='yellow')
current_scheduler.setup_schedule()
Expand Down

0 comments on commit 2974aeb

Please sign in to comment.