From c8ae72893ab6cb02763edeb258f8fa0a1d7cf721 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 24 Aug 2022 09:39:24 +0200 Subject: [PATCH] fix: clear queue on cancelling jobs --- apps/api/src/jobs/deployApplication.ts | 4 ++++ apps/api/src/lib/common.ts | 17 +++++++++-------- apps/api/src/lib/scheduler.ts | 3 ++- package.json | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts index 9259e3976..19899d900 100644 --- a/apps/api/src/jobs/deployApplication.ts +++ b/apps/api/src/jobs/deployApplication.ts @@ -28,6 +28,10 @@ import * as buildpacks from '../lib/buildPacks'; parentPort.postMessage({ size: queue.size, pending: queue.pending, caller: 'cleanupStorage' }); return; } + if (message === 'action:flushQueue') { + queue.clear() + return; + } await queue.add(async () => { const { diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 1a78a47af..379f79a34 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -17,8 +17,9 @@ import { checkContainer, removeContainer } from './docker'; import { day } from './dayjs'; import * as serviceFields from './serviceFields' import { saveBuildLog } from './buildPacks/common'; +import { scheduler } from './scheduler'; -export const version = '3.8.0'; +export const version = '3.8.1'; export const isDev = process.env.NODE_ENV === 'development'; const algorithm = 'aes-256-ctr'; @@ -1879,6 +1880,10 @@ export async function stopBuild(buildId, applicationId) { } if (count > 50) { clearInterval(interval); + if (scheduler.workers.has('deployApplication')) { + scheduler.workers.get('deployApplication').postMessage("action:flushQueue") + } + await cleanupDB(buildId); return reject(new Error('Build canceled')); } const { stdout: buildContainers } = await executeDockerCmd({ dockerId, command: `docker container ls --filter "label=coolify.buildId=${buildId}" --format '{{json .}}'` }) @@ -1889,15 +1894,14 @@ export async function stopBuild(buildId, applicationId) { const id = containerObj.ID; if (!containerObj.Names.startsWith(`${applicationId} `)) { await removeContainer({ id, dockerId }); + clearInterval(interval); return resolve(); } } } count++; - } catch (error) { } finally { - await cleanupDB(buildId); - } + } catch (error) { } }, 100); }); } @@ -1914,10 +1918,7 @@ export function convertTolOldVolumeNames(type) { return 'nc' } } -// export async function getAvailableServices(): Promise { -// const { data } = await axios.get(`https://gist.githubusercontent.com/andrasbacsai/4aac36d8d6214dbfc34fa78110554a50/raw/5b27e6c37d78aaeedc1148d797112c827a2f43cf/availableServices.json`) -// return data -// + export async function cleanupDockerStorage(dockerId, lowDiskSpace, force) { // Cleanup old coolify images try { diff --git a/apps/api/src/lib/scheduler.ts b/apps/api/src/lib/scheduler.ts index b120dcea1..5d8a57844 100644 --- a/apps/api/src/lib/scheduler.ts +++ b/apps/api/src/lib/scheduler.ts @@ -2,7 +2,8 @@ import Bree from 'bree'; import path from 'path'; import Cabin from 'cabin'; import TSBree from '@breejs/ts-worker'; -import { isDev } from './common'; + +export const isDev = process.env.NODE_ENV === 'development'; Bree.extend(TSBree); diff --git a/package.json b/package.json index 99cd0a1e6..9d6fd9250 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coolify", "description": "An open-source & self-hostable Heroku / Netlify alternative.", - "version": "3.8.0", + "version": "3.8.1", "license": "Apache-2.0", "repository": "github:coollabsio/coolify", "scripts": {