From fd17167d53cc6d110dafaf756c553f6f76885f3d Mon Sep 17 00:00:00 2001 From: Rohit Date: Sun, 26 Jan 2025 23:46:24 +0530 Subject: [PATCH] feat: set run failed on system interruption --- server/src/server.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/src/server.ts b/server/src/server.ts index 8c28c2d2..581ecadc 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -18,6 +18,7 @@ import { fork } from 'child_process'; import { capture } from "./utils/analytics"; import swaggerUi from 'swagger-ui-express'; import swaggerSpec from './swagger/config'; +import Run from './models/Run'; const app = express(); app.use(cors({ @@ -113,8 +114,23 @@ server.listen(SERVER_PORT, '0.0.0.0', async () => { } }); -process.on('SIGINT', () => { +process.on('SIGINT', async () => { console.log('Main app shutting down...'); + try { + await Run.update( + { + status: 'failed', + finishedAt: new Date().toLocaleString(), + log: 'Process interrupted during execution - worker shutdown' + }, + { + where: { status: 'running' } + } + ); + } catch (error: any) { + console.error('Error updating runs:', error); + } + if (!isProduction) { workerProcess.kill(); }