make scheduler setup more robust against wrong scheduling

is the schedule input is incorrect, an error message is logged and the plugin will NOT run.
Creating a dummy schedule would throw the system out of balance as there's the danger of schedules running out of sync.
This commit is contained in:
Ingo Ratsdorf
2025-09-27 16:52:50 +12:00
parent 2c8fa55edb
commit 4fef4a7dd4

View File

@@ -368,8 +368,19 @@ def importConfigs (pm, db, all_plugins):
# mylog('verbose', [f"[Config] pref {plugin["unique_prefix"]} run_val {run_val} run_sch {run_sch} "])
if run_val == 'schedule':
newSchedule = Cron(run_sch).schedule(start_date=datetime.datetime.now(conf.tz))
conf.mySchedules.append(schedule_class(plugin["unique_prefix"], newSchedule, newSchedule.next(), False))
newSchedule = None
try:
newSchedule = Cron(run_sch).schedule(start_date=datetime.datetime.now(conf.tz))
if (newSchedule is not None):
conf.mySchedules.append(schedule_class(plugin["unique_prefix"], newSchedule, newSchedule.next(), False))
else:
raise(ValueError("Invalid schedule"))
except ValueError as e:
mylog('none', [f"[Config] [ERROR] Invalid schedule '{run_sch}' for plugin '{plugin['unique_prefix']}'. Error: {e}."])
except Exception as e:
mylog('none', [f"[Config] [ERROR] Could not set schedule '{run_sch}' for plugin '{plugin['unique_prefix']}'. Error: {e}."])
# mylog('verbose', [f"[Config] conf.mySchedules {conf.mySchedules}"])