Skip to content

Commit

Permalink
fix: Duplicate scheduled jobs run forever
Browse files Browse the repository at this point in the history
If same method is added in multiple places our code just finds 1 random
scheduled job type and updates it as "ran", in some unlucky situations
this behaviour won't be random and always run one and update another so
the job never gets marked as "ran" and keeps running on every tick.
  • Loading branch information
ankush committed May 26, 2024
1 parent d18f743 commit e2252c0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frappe/core/doctype/scheduled_job_type/scheduled_job_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def enqueue(self, force=False) -> bool:
enqueue(
"frappe.core.doctype.scheduled_job_type.scheduled_job_type.run_scheduled_job",
queue=self.get_queue_name(),
job_type=self.method,
job_type=self.method, # Not actually used, kept for logging
job_id=self.rq_job_id,
scheduled_job_type=self.name,
)
return True
else:
Expand All @@ -93,7 +94,7 @@ def is_job_in_queue(self) -> bool:
@property
def rq_job_id(self):
"""Unique ID created to deduplicate jobs with single RQ call."""
return f"scheduled_job::{self.method}"
return f"scheduled_job::{self.name}"

@property
def next_execution(self):
Expand Down Expand Up @@ -188,10 +189,10 @@ def execute_event(doc: str):
return doc


def run_scheduled_job(job_type: str):
def run_scheduled_job(scheduled_job_type: str, job_type: str | None = None):
"""This is a wrapper function that runs a hooks.scheduler_events method"""
try:
frappe.get_doc("Scheduled Job Type", dict(method=job_type)).execute()
frappe.get_doc("Scheduled Job Type", scheduled_job_type).execute()
except Exception:
print(frappe.get_traceback())

Expand Down

0 comments on commit e2252c0

Please sign in to comment.