From febef372b892693e4f6c4f984db0411d7e0de601 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 6 May 2022 08:42:06 +0200 Subject: [PATCH] fix: Cancel jobs --- src/routes/applications/[id]/cancel.json.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/routes/applications/[id]/cancel.json.ts b/src/routes/applications/[id]/cancel.json.ts index 11c83ae9c..b81909887 100644 --- a/src/routes/applications/[id]/cancel.json.ts +++ b/src/routes/applications/[id]/cancel.json.ts @@ -22,16 +22,17 @@ export const post: RequestHandler = async (event) => { } = job.data; const host = getEngine(engine); let interval = setInterval(async () => { - const { status } = await db.prisma.build.findUnique({ where: { id: buildId } }); - if (status === 'failed') { - clearInterval(interval); - return resolve(); - } - if (count > 1200) { - clearInterval(interval); - reject(new Error('Could not cancel build.')); - } try { + const data = await db.prisma.build.findUnique({ where: { id: buildId } }); + if (data?.status === 'failed') { + clearInterval(interval); + return resolve(); + } + if (count > 60) { + clearInterval(interval); + reject(new Error('Could not cancel build.')); + } + const { stdout: buildContainers } = await asyncExecShell( `DOCKER_HOST=${host} docker container ls --filter "label=coolify.buildId=${buildId}" --format '{{json .}}'` ); @@ -53,7 +54,7 @@ export const post: RequestHandler = async (event) => { } count++; } catch (error) {} - }, 100); + }, 1000); resolve(); });