From ea693c4737a685e6df4cdf218c5b69171585a4bf Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 3 Feb 2026 15:08:09 +0530 Subject: [PATCH] Run interval tasks in coroutines to prevent blocking Wrap task callbacks in go() coroutines so long-running tasks like cleanupStaleExecutions don't block other timers from firing on schedule. Also re-enables the cleanupStaleExecutions task. --- src/Appwrite/Platform/Tasks/Interval.php | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Interval.php b/src/Appwrite/Platform/Tasks/Interval.php index 6d431705ab..bf14aa2512 100644 --- a/src/Appwrite/Platform/Tasks/Interval.php +++ b/src/Appwrite/Platform/Tasks/Interval.php @@ -58,15 +58,18 @@ class Interval extends Action $tasks = $this->getTasks(); foreach ($tasks as $task) { $timers[] = Timer::tick($task['interval'], function () use ($task, $dbForPlatform, $getProjectDB, $queueForCertificates) { - $taskName = $task['name']; - Span::init("interval.{$taskName}"); - try { - $task['callback']($dbForPlatform, $getProjectDB, $queueForCertificates); - } catch (\Exception $e) { - Span::error($e); - } finally { - Span::current()->finish(); - } + // Run each task in a coroutine to prevent blocking other timers + go(function () use ($task, $dbForPlatform, $getProjectDB, $queueForCertificates) { + $taskName = $task['name']; + Span::init("interval.{$taskName}"); + try { + $task['callback']($dbForPlatform, $getProjectDB, $queueForCertificates); + } catch (\Exception $e) { + Span::error($e); + } finally { + Span::current()->finish(); + } + }); }); } return $timers; @@ -84,7 +87,14 @@ class Interval extends Action $this->verifyDomain($dbForPlatform, $queueForCertificates); }, 'interval' => $intervalDomainVerification * 1000, - ] + ], + [ + 'name' => 'cleanupStaleExecutions', + "callback" => function (Database $dbForPlatform, callable $getProjectDB, Certificate $queueForCertificates) { + $this->cleanupStaleExecutions($dbForPlatform, $getProjectDB); + }, + 'interval' => $intervalCleanupStaleExecutions * 1000, + ], ]; }