Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def crontab_line(self) -> str | None:
f"{self.crontab.minute} {self.crontab.hour} {self.crontab.day_of_month} "
f"{self.crontab.month_of_year} {self.crontab.day_of_week}"
)
return None

@crontab_line.setter
def crontab_line(self, value: str):
Expand All @@ -650,25 +651,43 @@ def save(self, *args, **kwargs):
space_user_code = f"{self.space.space_code}.{self.workflow_user_code}"
if not self.name:
self.name = f"periodic-{space_user_code}-{self.crontab_line}"
self.args = json.dumps([space_user_code, self.payload, self.is_manager])
self.args = json.dumps(
[
space_user_code,
self.payload,
self.is_manager,
]
)
self.crontab, _ = CrontabSchedule.objects.get_or_create(
minute=self.crontab.minute,
hour=self.crontab.hour,
day_of_month=self.crontab.day_of_month,
month_of_year=self.crontab.month_of_year,
day_of_week=self.crontab.day_of_week,
)

creating = self.pk is None

if creating:
super().save(*args, **kwargs)

self.kwargs = json.dumps(
{
"context": {
"realm_code": self.space.realm_code,
"space_code": self.space.space_code,
},
"crontab_id": self.crontab.id,
"schedule_id": self.id,
"schedule_id": self.pk,
}
)
_l.info("Schedule save: %s", self.kwargs)

if creating:
using = kwargs.get("using")
super().save(using=using, update_fields=["kwargs"])
return

return super().save(*args, **kwargs)

def __str__(self):
Expand Down