mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
refactor: inject build timeout when initializing deployments
This commit is contained in:
1 parent
2b147bf98c
commit
04f164f64c
6 files changed
+10
-19
No files matched your search
@@ -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(), []);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<string, mixed> 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)];
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user