From 109d12b181a467575a20e4d9f511a64d59a4a0f7 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:07:26 +0100 Subject: [PATCH] Migrate screenshots worker to utopia-php/client Replaces utopia-php/fetch with the PSR-18 utopia-php/client already used by the jobs client. The client and request factory are built once per message instead of per screenshot, and the timeout is now passed in seconds instead of milliseconds to match the new client's API. Co-Authored-By: Claude Fable 5 --- .../Modules/Functions/Workers/Screenshots.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php index 35cbe63a15..aeb3259645 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php @@ -8,14 +8,17 @@ use Appwrite\Event\Realtime; use Appwrite\Permission; use Appwrite\Role; use Exception; +use Utopia\Client; +use Utopia\Client\Adapter\Curl\Client as CurlAdapter; use Utopia\Compression\Compression; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; -use Utopia\Fetch\Client as FetchClient; use Utopia\Platform\Action; +use Utopia\Psr7\Method; +use Utopia\Psr7\Request\Factory as RequestFactory; use Utopia\Queue\Message; use Utopia\Span\Span; use Utopia\Storage\Device; @@ -111,7 +114,7 @@ class Screenshots extends Action throw new \Exception("Rule for deployment not found"); } - $timeout = \intval($site->getAttribute('timeout', '15')) * 1000; + $timeout = \intval($site->getAttribute('timeout', '15')); $bucket = $dbForPlatform->getDocument('buckets', 'screenshots'); @@ -161,9 +164,13 @@ class Screenshots extends Action 'deploymentStatusIgnored' => true ]); + $browserEndpoint = System::getEnv('_APP_BROWSER_HOST', 'http://appwrite-browser:3000/v1'); + $client = (new Client(new CurlAdapter()))->withTimeout($timeout); + $factory = new RequestFactory(); + $screenshotError = null; - $screenshots = batch(\array_map(function ($key) use ($configs, $apiKey, $site, $timeout, &$screenshotError) { - return function () use ($key, $configs, $apiKey, $site, $timeout, &$screenshotError) { + $screenshots = batch(\array_map(function ($key) use ($configs, $apiKey, $site, $browserEndpoint, $client, $factory, &$screenshotError) { + return function () use ($key, $configs, $apiKey, $site, $browserEndpoint, $client, $factory, &$screenshotError) { try { $config = $configs[$key]; @@ -178,22 +185,13 @@ class Screenshots extends Action $config['sleep'] = $framework['screenshotSleep']; } - $browserEndpoint = System::getEnv('_APP_BROWSER_HOST', 'http://appwrite-browser:3000/v1'); - $client = new FetchClient(); - $client->setTimeout($timeout); - $client->addHeader('content-type', FetchClient::CONTENT_TYPE_APPLICATION_JSON); + $response = $client->sendRequest($factory->json(Method::POST, $browserEndpoint . '/screenshots', $config)); - $fetchResponse = $client->fetch( - url: $browserEndpoint . '/screenshots', - method: 'POST', - body: $config - ); - - if ($fetchResponse->getStatusCode() >= 400) { - throw new \Exception($fetchResponse->getBody()); + if ($response->getStatusCode() >= 400) { + throw new \Exception((string)$response->getBody()); } - $screenshot = $fetchResponse->getBody(); + $screenshot = (string)$response->getBody(); return ['key' => $key, 'screenshot' => $screenshot]; } catch (\Throwable $th) {