fix: join output failures with exit measurements before billing

This commit is contained in:
loks0n committed 2026-09-14 12:28:04 +01:00
1 parent f0018f73ad
commit b6adab0fad
2 files changed
+21 -8

No files matched your search

@@ -298,7 +298,11 @@ class Jobs extends Action
// the queue can deliver those callbacks out of order.
if ($artifact->artifactId === 'output') {
if ($failed) {
return $this->finalize($dbForProject, $dbForPlatform, $project, $deployment, false, 'Build output upload failed: ' . ($artifact->error->message ?? 'unknown error'), $usage, $publisherForUsage, $publisherForScreenshots, $vcsFactory, $platform, $bus);
// Output delivery can fail before the exit callback arrives.
// Join the exit first so usage uses the worker's measurement.
$cache->save('jobs-output-' . $deployment->getId(), ['error' => 'Build output upload failed: ' . ($artifact->error->message ?? 'unknown error')]);
return $this->ready($dbForProject, $dbForPlatform, $project, $deployment, $usage, $publisherForUsage, $publisherForScreenshots, $deviceForBuilds, $vcsFactory, $cache, $platform, $plan, $bus);
}
if ($artifact->status !== 'success') {
@@ -444,11 +448,20 @@ class Jobs extends Action
$deploymentId = $deployment->getId();
$isSite = $deployment->getAttribute('resourceType') === 'sites';
if ($cache->load('jobs-exit-' . $deploymentId, self::DEDUPE_TTL) === false || $cache->load('jobs-complete-' . $deploymentId, self::DEDUPE_TTL) === false) {
if ($cache->load('jobs-exit-' . $deploymentId, self::DEDUPE_TTL) === false) {
return $deployment;
}
if ($deviceForBuilds->getType() !== DeviceType::Local && $cache->load('jobs-output-' . $deploymentId, self::DEDUPE_TTL) === false) {
$output = $cache->load('jobs-output-' . $deploymentId, self::DEDUPE_TTL);
if (\is_array($output) && isset($output['error'])) {
return $this->finalize($dbForProject, $dbForPlatform, $project, $deployment, false, $output['error'], $usage, $publisherForUsage, $publisherForScreenshots, $vcsFactory, $platform, $bus);
}
if ($cache->load('jobs-complete-' . $deploymentId, self::DEDUPE_TTL) === false) {
return $deployment;
}
if ($deviceForBuilds->getType() !== DeviceType::Local && $output === false) {
return $deployment;
}
+5 -5
View File
@@ -20,17 +20,17 @@ final class BuildTimeoutTest extends TestCase
{
public static function budgets(): \Iterator
{
yield 'default' => [null, 900];
yield 'operator override' => ['1800', 1800];
yield 'short operator budget' => [37];
yield 'long operator budget' => [1823];
}
#[DataProvider('budgets')]
public function testSelfHostedSubmissionUsesOperatorBudget(?string $configured, int $expected): void
public function testSelfHostedSubmissionUsesOperatorBudget(int $configured): void
{
$previousKey = getenv('_APP_OPENSSL_KEY_V1');
$previousTimeout = getenv('_APP_COMPUTE_BUILD_TIMEOUT');
putenv('_APP_OPENSSL_KEY_V1=unit-test-key');
putenv($configured === null ? '_APP_COMPUTE_BUILD_TIMEOUT' : '_APP_COMPUTE_BUILD_TIMEOUT=' . $configured);
putenv('_APP_COMPUTE_BUILD_TIMEOUT=' . $configured);
try {
$deployment = new Document(['$id' => 'deployment', '$sequence' => '1', 'type' => 'manual', 'buildCommands' => 'npm ci']);
$database = $this->createStub(Database::class);
@@ -58,7 +58,7 @@ final class BuildTimeoutTest extends TestCase
$this->assertSame('waiting', $result->getAttribute('status'));
$this->assertCount(1, $requests);
$this->assertSame($expected, $requests[0]['timeoutSeconds']);
$this->assertSame($configured, $requests[0]['timeoutSeconds']);
} finally {
putenv($previousKey === false ? '_APP_OPENSSL_KEY_V1' : '_APP_OPENSSL_KEY_V1=' . $previousKey);
putenv($previousTimeout === false ? '_APP_COMPUTE_BUILD_TIMEOUT' : '_APP_COMPUTE_BUILD_TIMEOUT=' . $previousTimeout);