Crontab fixes

This commit is contained in:
Ariel Rin 2025-02-25 09:16:59 +00:00
parent 02214b74d0
commit c1e2449084

View File

@ -20,6 +20,10 @@ class OffsetDatabaseScheduler(DatabaseScheduler):
Takes the Celery Schedule from local.py and applies our AA Framework Cron Offset, if apply_offset is true
Otherwise it passes it through as normal
"""
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
def update_from_dict(self, mapping):
s = {}
@ -36,10 +40,10 @@ class OffsetDatabaseScheduler(DatabaseScheduler):
for name, entry_fields in mapping.items():
try:
apply_offset = entry_fields.pop("apply_offset", False)
apply_offset = entry_fields.pop("apply_offset", False) # Ensure this pops before django tries to save to ORM
entry = self.Entry.from_entry(name, app=self.app, **entry_fields)
if entry.model.enabled and apply_offset:
if apply_offset:
schedule_obj = entry.schedule
if isinstance(schedule_obj, schedules.crontab):
offset_cs = CrontabSchedule.from_schedule(offset_cron(schedule_obj))
@ -55,7 +59,8 @@ class OffsetDatabaseScheduler(DatabaseScheduler):
entry.model.save()
logger.debug(f"Offset applied for '{name}' due to 'apply_offset' = True.")
s[name] = entry
if entry.model.enabled:
s[name] = entry
except Exception as e:
logger.exception("Error updating schedule for %s: %r", name, e)