diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 00d5dfabe4..22754e2489 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -207,7 +207,7 @@ return function (Container $context): void { // Builds a Deployments bound to a given project — webhook handlers resolve // their tenant projects mid-request, after this container is initialized. $context->set('deploymentsFactory', function (Jobs $jobs, array $platform) { - return fn (Database $dbForProject, Document $project): Deployments => new Deployments($jobs, $dbForProject, $project, $platform); + return fn (Database $dbForProject, Document $project): Deployments => new Deployments($jobs, $dbForProject, $project, $platform, (int) System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900)); }, ['jobs', 'platform']); $context->set('deployments', fn (callable $deploymentsFactory, Database $dbForProject, Document $project) => $deploymentsFactory($dbForProject, $project), ['deploymentsFactory', 'dbForProject', 'project']); $context->set('eventProcessor', fn () => new EventProcessor(), []); diff --git a/app/init/worker/message.php b/app/init/worker/message.php index 4c1182fa65..76f53b04e8 100644 --- a/app/init/worker/message.php +++ b/app/init/worker/message.php @@ -174,7 +174,7 @@ return function (Container $container): void { // Only the Builds worker uses this, handing template-into-repo pushes to // the jobs-service. $container->set('deployments', function (Jobs $jobs, Database $dbForProject, Document $project, array $platform) { - return new Deployments($jobs, $dbForProject, $project, $platform); + return new Deployments($jobs, $dbForProject, $project, $platform, (int) System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900)); }, ['jobs', 'dbForProject', 'project', 'platform']); $container->set('getAudit', function (Database $dbForPlatform, callable $getProjectDB) { diff --git a/src/Appwrite/Deployment/Deployments.php b/src/Appwrite/Deployment/Deployments.php index a4bfc66cd7..5ad547acd5 100644 --- a/src/Appwrite/Deployment/Deployments.php +++ b/src/Appwrite/Deployment/Deployments.php @@ -62,6 +62,7 @@ readonly class Deployments protected Database $dbForProject, protected Document $project, private array $platform, + private int $timeout, ) { } @@ -221,7 +222,7 @@ readonly class Deployments } try { - $this->jobs->create(...static::payload($this->project, $resource, $deployment, $this->platform, $source, $this->timeout())); + $this->jobs->create(...static::payload($this->project, $resource, $deployment, $this->platform, $this->timeout, $source)); } catch (\Throwable $error) { // A refused variable key is the owner's to fix, so the build log // carries the actual reason; anything else stays a generic @@ -339,16 +340,6 @@ readonly class Deployments return 'cd /usr/local/server/src/function/ && ' . $escaped; } - /** - * Editions may resolve a project-specific build budget here. The same - * budget governs the job and the credentials it needs while building. - */ - protected function timeout(): int - { - // Self-hosted operators configure the build budget; default to 15 minutes. - return (int) System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900); - } - /** * @return array Named arguments for OpenRuntimes\Orchestrator\Jobs::create(). */ @@ -357,13 +348,12 @@ readonly class Deployments Document $resource, Document $deployment, array $platform, + int $timeout, ?array $source = null, - ?int $timeout = null, ): array { $projectId = $project->getId(); $deploymentId = $deployment->getId(); $isSite = $resource->getCollection() === 'sites'; - $timeout ??= (int) System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900); $runtime = self::runtime($resource, self::version($resource)); $spec = Config::getParam('specifications')[$resource->getAttribute('buildSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT)]; diff --git a/tests/unit/Deployment/BuildTimeoutTest.php b/tests/unit/Deployment/BuildTimeoutTest.php index 191a7c3c5b..98f2d78d98 100644 --- a/tests/unit/Deployment/BuildTimeoutTest.php +++ b/tests/unit/Deployment/BuildTimeoutTest.php @@ -25,7 +25,7 @@ final class BuildTimeoutTest extends TestCase } #[DataProvider('budgets')] - public function testSelfHostedSubmissionUsesOperatorBudget(int $configured): void + public function testSubmissionUsesConstructorBudget(int $configured): void { $previousKey = getenv('_APP_OPENSSL_KEY_V1'); $previousTimeout = getenv('_APP_COMPUTE_BUILD_TIMEOUT'); @@ -49,7 +49,8 @@ final class BuildTimeoutTest extends TestCase $requests[] = json_decode((string) $request->getBody(), true, flags: JSON_THROW_ON_ERROR); return new Response(202, body: new Stream('{"id":"build","status":"accepted"}')); }); - $service = new Deployments(new Jobs($client), $database, new Document(['$id' => 'project', 'region' => 'default']), ['apiHostname' => 'localhost']); + $service = new Deployments(new Jobs($client), $database, new Document(['$id' => 'project', 'region' => 'default']), ['apiHostname' => 'localhost'], $configured); + putenv('_APP_COMPUTE_BUILD_TIMEOUT=1'); $result = $service->createFromUpload(new Document([ '$id' => 'function', '$collection' => 'functions', diff --git a/tests/unit/Deployment/DeploymentsTest.php b/tests/unit/Deployment/DeploymentsTest.php index de41f435d3..313224ebd6 100644 --- a/tests/unit/Deployment/DeploymentsTest.php +++ b/tests/unit/Deployment/DeploymentsTest.php @@ -180,6 +180,6 @@ final readonly class ExposedDeployments extends Deployments { public static function submitPayload(Document $project, Document $resource, Document $deployment, array $platform): array { - return static::payload($project, $resource, $deployment, $platform); + return static::payload($project, $resource, $deployment, $platform, 900); } } diff --git a/tests/unit/Deployment/UploadCallbacksTest.php b/tests/unit/Deployment/UploadCallbacksTest.php index c434be4c7a..13d71dda2b 100644 --- a/tests/unit/Deployment/UploadCallbacksTest.php +++ b/tests/unit/Deployment/UploadCallbacksTest.php @@ -39,7 +39,7 @@ final class UploadCallbacksTest extends TestCase $requests[] = json_decode((string) $request->getBody(), true, flags: JSON_THROW_ON_ERROR); return new Response(202, body: new Stream('{"id":"build","status":"accepted"}')); }); - $deployments = new Deployments(new Jobs($client), $database, new Document(['$id' => 'project', 'region' => 'default']), ['apiHostname' => 'localhost']); + $deployments = new Deployments(new Jobs($client), $database, new Document(['$id' => 'project', 'region' => 'default']), ['apiHostname' => 'localhost'], 900); $result = $deployments->createFromUpload(new Document([ '$id' => 'function', '$collection' => 'functions', 'runtime' => array_key_first(Config::getParam('runtimes-v2')), ]), clone $deployment);