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 <noreply@anthropic.com>
This commit is contained in:
loks0nandClaude Fable 5 committed 2026-07-10 20:07:26 +01:00
1 parent 1c5c955882
commit 109d12b181
1 file changed
+15 -17
@@ -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) {