fix: Cancel old builds in database

This commit is contained in:
Andras Bacsai 2022-05-06 09:55:39 +02:00
parent febef372b8
commit b0eae8cfe9

View File

@ -17,9 +17,12 @@ export const post: RequestHandler = async (event) => {
let count = 0; let count = 0;
await new Promise<void>(async (resolve, reject) => { await new Promise<void>(async (resolve, reject) => {
const job = await buildQueue.getJob(buildId); const job = await buildQueue.getJob(buildId);
if (!job) {
return resolve();
}
const { const {
destinationDocker: { engine } destinationDocker: { engine }
} = job.data; } = job?.data;
const host = getEngine(engine); const host = getEngine(engine);
let interval = setInterval(async () => { let interval = setInterval(async () => {
try { try {
@ -58,7 +61,10 @@ export const post: RequestHandler = async (event) => {
resolve(); resolve();
}); });
const data = await db.prisma.build.findUnique({ where: { id: buildId } });
if (data?.status === 'queued' || data?.status === 'running') {
await db.prisma.build.update({ where: { id: buildId }, data: { status: 'failed' } });
}
return { return {
status: 200, status: 200,
body: { body: {