mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
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.
This commit is contained in:
@@ -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,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user