Compare commits

...
Author SHA1 Message Date
Chirag Aggarwal ea693c4737 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.
2026-02-03 15:08:09 +05:30
+20 -10
View File
@@ -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,
],
];
}