Skip to content

Commit

Permalink
Fix check for task based on schedule_id
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbruinsslot committed Nov 28, 2024
1 parent c243550 commit e242248
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions mula/scheduler/schedulers/schedulers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,21 @@ def push_tasks_for_rescheduling(self):
for schedule in schedules:
report_task = ReportTask.model_validate(schedule.data)

# When the schedule has no schedule, but a task is
# already executed we should not push the task again
task_db = None
# When the schedule has no schedule (cron expression), but a
# task is already executed for this schedule we should not run
# the task again
try:
task_db = self.ctx.datastores.task_store.get_latest_task_by_hash(report_task.hash)
if task_db and schedule.schedule is None:
_, count = self.ctx.datastores.task_store.get_tasks(
scheduler_id=self.scheduler_id,
task_type=report_task.type,
filters=filters.FilterRequest(
filters=[
filters.Filter(column="hash", operator="eq", value=report_task.hash),
filters.Filter(column="schedule_id", operator="eq", value=schedule.id),
]
),
)
if count > 0 and schedule.schedule is None:
self.logger.debug(
"Schedule has no schedule, but task already executed",
schedule_id=schedule.id,
Expand Down

0 comments on commit e242248

Please sign in to comment.