From 50005340134e17f77aa98c070ac5190a5d436ff1 Mon Sep 17 00:00:00 2001 From: leffss <348926676@qq.com> Date: Tue, 2 Aug 2022 10:19:59 +0800 Subject: [PATCH] update CustomScheduleEntry --- redismultibeat/scheduler.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/redismultibeat/scheduler.py b/redismultibeat/scheduler.py index 488209e..b22c92d 100644 --- a/redismultibeat/scheduler.py +++ b/redismultibeat/scheduler.py @@ -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) @@ -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