Merge branch 'crontab' into 'master'

Crontab fixes

See merge request allianceauth/allianceauth!1686
This commit is contained in:
Ariel Rin 2025-02-25 09:16:59 +00:00
commit 7b92d103d6

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 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 Otherwise it passes it through as normal
""" """
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
def update_from_dict(self, mapping): def update_from_dict(self, mapping):
s = {} s = {}
@ -36,10 +40,10 @@ class OffsetDatabaseScheduler(DatabaseScheduler):
for name, entry_fields in mapping.items(): for name, entry_fields in mapping.items():
try: 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) 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 schedule_obj = entry.schedule
if isinstance(schedule_obj, schedules.crontab): if isinstance(schedule_obj, schedules.crontab):
offset_cs = CrontabSchedule.from_schedule(offset_cron(schedule_obj)) offset_cs = CrontabSchedule.from_schedule(offset_cron(schedule_obj))
@ -55,6 +59,7 @@ class OffsetDatabaseScheduler(DatabaseScheduler):
entry.model.save() entry.model.save()
logger.debug(f"Offset applied for '{name}' due to 'apply_offset' = True.") logger.debug(f"Offset applied for '{name}' due to 'apply_offset' = True.")
if entry.model.enabled:
s[name] = entry s[name] = entry
except Exception as e: except Exception as e: