From 6a712e236d91e0acaaee940d34bc6b2531625c0f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:46:13 +0000 Subject: [PATCH 1/2] Initial plan From e4ebf755e414b9d3517628170069cf3b6ae38152 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:50:32 +0000 Subject: [PATCH 2/2] 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> --- .../Platform/Tasks/ScheduleExecutions.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index 3f08815d8c..cd7873bab6 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -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']]); } } }