From 5e35b4bac17ce9226e7572f6ab30b6d73f64a244 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:35:09 +0100 Subject: [PATCH] Capture themes sequentially; rely on worker coroutines for concurrency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screenshots worker already runs with _APP_WORKERS_NUM=1 and _APP_WORKER_MAX_COROUTINES=8, so per-message batch() fan-out is redundant — concurrency across messages comes from the queue adapter. Capturing light/dark sequentially deletes the task closures and lets failures propagate as plain exceptions. Co-Authored-By: Claude Fable 5 --- .../Modules/Functions/Workers/Screenshots.php | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php index 27de5414ce..3fce845324 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php @@ -23,8 +23,6 @@ use Utopia\System\System; use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Telemetry\Counter; -use function Swoole\Coroutine\batch; - class Screenshots extends Action { public static function getName(): string @@ -156,29 +154,16 @@ class Screenshots extends Action $framework = Config::getParam('frameworks', [])[$site->getAttribute('framework', '')] ?? null; $sleep = $framework['screenshotSleep'] ?? 3000; - $tasks = []; - foreach (['screenshotLight' => 'light', 'screenshotDark' => 'dark'] as $key => $theme) { - // batch() doesn't propagate exceptions out of coroutines; return them instead. - $tasks[] = function () use ($key, $theme, $screenshots, $routerHost, $headers, $sleep) { - try { - return ['key' => $key, 'screenshot' => $screenshots->create( - url: $routerHost . '/?appwrite-preview=1&appwrite-theme=' . $theme, - theme: $theme, - headers: $headers, - sleep: $sleep, - )]; - } catch (\Throwable $th) { - return $th; - } - }; - } - + // Concurrency comes from the worker's coroutines (_APP_WORKER_MAX_COROUTINES), + // so the two themes are captured sequentially within a message. $captures = []; - foreach (batch($tasks) as $capture) { - if ($capture instanceof \Throwable) { - throw $capture; - } - $captures[] = $capture; + foreach (['screenshotLight' => 'light', 'screenshotDark' => 'dark'] as $key => $theme) { + $captures[$key] = $screenshots->create( + url: $routerHost . '/?appwrite-preview=1&appwrite-theme=' . $theme, + theme: $theme, + headers: $headers, + sleep: $sleep, + ); } Span::add('screenshot.count', \count($captures)); @@ -186,10 +171,7 @@ class Screenshots extends Action $mimeType = "image/png"; $updates = new Document([]); - foreach ($captures as $data) { - $key = $data['key']; - $screenshot = $data['screenshot']; - + foreach ($captures as $key => $screenshot) { $fileId = ID::unique(); $fileName = $fileId . '.png'; $path = $deviceForFiles->getPath($fileName);