From 0faa1540f448cd7610245877567979c4d221d856 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 May 2022 14:42:19 +0200 Subject: [PATCH] ui fixes --- src/routes/applications/[id]/cancel.json.ts | 12 +++++--- .../[id]/logs/build/_BuildLog.svelte | 29 ++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/routes/applications/[id]/cancel.json.ts b/src/routes/applications/[id]/cancel.json.ts index ce1082a33..11c83ae9c 100644 --- a/src/routes/applications/[id]/cancel.json.ts +++ b/src/routes/applications/[id]/cancel.json.ts @@ -15,15 +15,19 @@ export const post: RequestHandler = async (event) => { } try { let count = 0; - await new Promise(async (resolve, reject) => { + await new Promise(async (resolve, reject) => { const job = await buildQueue.getJob(buildId); const { destinationDocker: { engine } } = job.data; const host = getEngine(engine); let interval = setInterval(async () => { - console.log(`Checking build ${buildId}, try ${count}`); - if (count > 100) { + 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.')); } @@ -51,7 +55,7 @@ export const post: RequestHandler = async (event) => { } catch (error) {} }, 100); - resolve('Canceled'); + resolve(); }); return { diff --git a/src/routes/applications/[id]/logs/build/_BuildLog.svelte b/src/routes/applications/[id]/logs/build/_BuildLog.svelte index 4a761857d..378e58c2c 100644 --- a/src/routes/applications/[id]/logs/build/_BuildLog.svelte +++ b/src/routes/applications/[id]/logs/build/_BuildLog.svelte @@ -20,6 +20,8 @@ let followingInterval; let logsEl; + let cancelInprogress = false; + const { id } = $page.params; const cleanAnsiCodes = (str: string) => str.replace(/\x1B\[(\d+)m/g, ''); @@ -68,10 +70,17 @@ } } async function cancelBuild() { - return await post(`/applications/${id}/cancel.json`, { - buildId, - applicationId: id - }); + if (cancelInprogress) return; + try { + cancelInprogress = true; + await post(`/applications/${id}/cancel.json`, { + buildId, + applicationId: id + }); + } catch (error) { + console.log(error); + return errorNotification(error); + } } onDestroy(() => { clearInterval(streamInterval); @@ -96,7 +105,7 @@
{#if currentStatus === 'running'} - {/if}