Skip to content

Commit

Permalink
update CustomScheduleEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
leffss committed Aug 2, 2022
1 parent 6a7d0da commit 5000534
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions redismultibeat/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from celery.utils.log import get_logger
from redis.exceptions import LockError
import urllib.parse as urlparse
from kombu.utils.functional import reprcall

logger = get_logger(__name__)
debug, info, error, warning = (logger.debug, logger.info, logger.error, logger.warning)
Expand Down Expand Up @@ -131,6 +132,34 @@ def __reduce__(self):
self.schedule, self.args, self.kwargs, self.options,
)

def update(self, other):
"""Update values from another entry.
Will only update "editable" fields:
``task``, ``schedule``, ``args``, ``kwargs``, ``options``.
``limit_run_time``, ``enable``.
"""
self.__dict__.update({
'task': other.task, 'schedule': other.schedule,
'args': other.args, 'kwargs': other.kwargs,
'options': other.options, 'limit_run_time': other.limit_run_time,
'enable': other.enable
})

def __repr__(self):
return '<{name}: {0.name} {call} {0.schedule} limit_run_time: {0.limit_run_time} ' \
'enable: {0.enable} options: {0.options}>'.format(
self,
call=reprcall(self.task, self.args or (), self.kwargs or {}),
name=type(self).__name__,
)

def editable_fields_equal(self, other):
for attr in ('task', 'args', 'kwargs', 'options', 'schedule', 'limit_run_time', 'enable'):
if getattr(self, attr) != getattr(other, attr):
return False
return True


class RedisMultiScheduler(Scheduler):
Entry = CustomScheduleEntry
Expand Down

0 comments on commit 5000534

Please sign in to comment.