From 034606c6abe0c6ceaadd4753bc40c4f0213d3568 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 20:36:32 +0000 Subject: [PATCH] Fix inverted time comparison in ScheduleExecutions enqueueResources - Changed condition from <= to > to fix inverted logic - Compute $now once at top of method to avoid timestamp drift - Use $now for both $intervalEnd and $delay calculations - Clamp $delay to 0 to prevent negative values to Co::sleep Bug: The old code skipped schedules within the enqueue window and processed schedules far in the future (opposite of intended behavior) Co-authored-by: stnguyen90 <1477010+stnguyen90@users.noreply.github.com> --- .../Platform/Tasks/ScheduleExecutions.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index 83a3f51b03..54ccd65edd 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -34,7 +34,8 @@ class ScheduleExecutions extends ScheduleBase protected function enqueueResources(Database $dbForPlatform, callable $getProjectDB): void { - $intervalEnd = (new \DateTime())->modify('+' . self::ENQUEUE_TIMER . ' seconds'); + $now = new \DateTime(); + $intervalEnd = (clone $now)->modify('+' . self::ENQUEUE_TIMER . ' seconds'); $queueForFunctions = new Func($this->publisherFunctions); @@ -50,7 +51,10 @@ class ScheduleExecutions extends ScheduleBase } $scheduledAt = new \DateTime($schedule['schedule']); - if ($scheduledAt <= $intervalEnd) { + + // Only process schedules that fall within the enqueue window. + // If the scheduled time is after the window, skip it for now. + if ($scheduledAt > $intervalEnd) { continue; } @@ -59,7 +63,10 @@ class ScheduleExecutions extends ScheduleBase $schedule['$id'], )->getAttribute('data', []); - $delay = $scheduledAt->getTimestamp() - (new \DateTime())->getTimestamp(); + $delay = $scheduledAt->getTimestamp() - $now->getTimestamp(); + if ($delay < 0) { + $delay = 0; + } $this->updateProjectAccess($schedule['project'], $dbForPlatform); @@ -67,8 +74,6 @@ class ScheduleExecutions extends ScheduleBase Co::sleep($delay); $queueForFunctions->setType('schedule') - // Set functionId instead of function as we don't have $dbForProject - // TODO: Refactor to use function instead of functionId ->setFunctionId($schedule['resource']['resourceId']) ->setExecution($schedule['resource']) ->setMethod($data['method'] ?? 'POST')