Skip to content

Commit

Permalink
Merge pull request #1375 from argos-ci/process-build-only-once
Browse files Browse the repository at this point in the history
fix: process build only once
  • Loading branch information
gregberge authored Sep 8, 2024
2 parents bebfe02 + 613dd33 commit 01bc789
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/backend/src/api/handlers/finalizeBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,32 @@ export const finalizeBuilds: CreateAPIHandler = ({ post }) => {
.where("builds.externalId", parallelNonce)
.where("builds.totalBatch", -1);

await transaction(async (trx) => {
await Promise.all(
const finalized = await transaction(async (trx) => {
return Promise.all(
builds.map(async (build) => {
invariant(build.compareScreenshotBucket);
const willFinalize = !build.compareScreenshotBucket.complete;

await Promise.all([
!build.compareScreenshotBucket.complete
? finalizeBuildService({ build, trx })
: null,
willFinalize ? finalizeBuildService({ build, trx }) : null,
// If the build was marked as partial, then it was obviously an error, we unmark it.
build.partial
? Build.query(trx).where("id", build.id).patch({ partial: false })
: null,
]);

return willFinalize;
}),
);
});

await Promise.all(builds.map((build) => buildJob.push(build.id)));
await Promise.all(
builds.map(async (build, index) => {
if (finalized[index]) {
await buildJob.push(build.id);
}
}),
);

const buildResponses = await serializeBuilds(builds);
res.send({ builds: buildResponses });
Expand Down

0 comments on commit 01bc789

Please sign in to comment.