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>
This commit is contained in:
copilot-swe-agent[bot]andstnguyen90 committed 2025-12-07 20:36:32 +00:00
1 parent 6fef4ea694
commit 034606c6ab
1 file changed
+10 -5
@@ -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')