fix: Update existing ScheduledJobType records
instead of deleting them and creating new records on migrate
This commit is contained in:
parent
8ef323e647
commit
fc8b0dc1f3
1 changed files with 22 additions and 12 deletions
|
|
@ -237,24 +237,34 @@ def insert_event_jobs(events: list, event_type: str) -> list:
|
|||
return event_jobs
|
||||
|
||||
|
||||
def insert_single_event(frequency: str, event: str, cron_format: str | None = None):
|
||||
cron_expr = {"cron_format": cron_format} if cron_format else {}
|
||||
|
||||
def insert_single_event(frequency: str, event: str, cron_format: str | None = ""):
|
||||
try:
|
||||
frappe.get_attr(event)
|
||||
except Exception as e:
|
||||
click.secho(f"{event} is not a valid method: {e}", fg="yellow")
|
||||
return
|
||||
|
||||
doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Scheduled Job Type",
|
||||
"method": event,
|
||||
"cron_format": cron_format,
|
||||
"frequency": frequency,
|
||||
}
|
||||
)
|
||||
doc: ScheduledJobType
|
||||
|
||||
if job_name := frappe.db.exists("Scheduled Job Type", {"method": event}):
|
||||
doc = frappe.get_doc("Scheduled Job Type", job_name)
|
||||
|
||||
# Update only frequency and cron_format fields if they are different
|
||||
# Maintain existing values of other fields
|
||||
if doc.frequency != frequency or doc.cron_format != cron_format:
|
||||
doc.cron_format = cron_format
|
||||
doc.frequency = frequency
|
||||
doc.save()
|
||||
else:
|
||||
doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Scheduled Job Type",
|
||||
"method": event,
|
||||
"cron_format": cron_format,
|
||||
"frequency": frequency,
|
||||
}
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Scheduled Job Type", {"method": event, "frequency": frequency, **cron_expr}):
|
||||
savepoint = "scheduled_job_type_creation"
|
||||
try:
|
||||
frappe.db.savepoint(savepoint)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue