Fix: Move schedule deletion inside coroutine to prevent job loss

Move the schedule document deletion and unset operation inside the coroutine, after the function is triggered. This ensures the schedule is only deleted after the job is successfully queued, preventing job loss if the container shuts down between coroutine start and completion.

This follows the same pattern used in ScheduleMessages.php.

Co-authored-by: stnguyen90 <1477010+stnguyen90@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-12-08 19:50:32 +00:00
parent 6a712e236d
commit e4ebf755e4

View file

@ -63,7 +63,7 @@ class ScheduleExecutions extends ScheduleBase
$this->updateProjectAccess($schedule['project'], $dbForPlatform);
\go(function () use ($queueForFunctions, $schedule, $scheduledAt, $delay, $data) {
\go(function () use ($queueForFunctions, $schedule, $scheduledAt, $delay, $data, $dbForPlatform) {
if ($delay > 0) {
Co::sleep($delay);
}
@ -81,15 +81,14 @@ class ScheduleExecutions extends ScheduleBase
->setUserId($data['userId'] ?? '')
->trigger();
$dbForPlatform->deleteDocument(
'schedules',
$schedule['$id'],
);
$this->recordEnqueueDelay($scheduledAt);
unset($this->schedules[$schedule['$sequence']]);
});
$dbForPlatform->deleteDocument(
'schedules',
$schedule['$id'],
);
unset($this->schedules[$schedule['$sequence']]);
}
}
}