From 040e19fdc2e03e241519e81d5bd7b4c866cf8b6b Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 15 Sep 2023 20:39:15 +0300 Subject: [PATCH] Interactive execution: run job cleanup regardless of errors --- api/src/api/v2.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/api/src/api/v2.js b/api/src/api/v2.js index ad07494..1b015b5 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -210,19 +210,26 @@ router.ws('/connect', async (ws, req) => { if (job === null) { job = await get_job(msg); - await job.prime(); + try { + await job.prime(); - ws.send( - JSON.stringify({ - type: 'runtime', - language: job.runtime.language, - version: job.runtime.version.raw, - }) - ); - - await job.execute(event_bus); - await job.cleanup(); + ws.send( + JSON.stringify({ + type: 'runtime', + language: job.runtime.language, + version: job.runtime.version.raw, + }) + ); + await job.execute(event_bus); + } catch (error) { + logger.error( + `Error cleaning up job: ${job.uuid}:\n${error}` + ); + throw error; + } finally { + await job.cleanup(); + } ws.close(4999, 'Job Completed'); } else { ws.close(4000, 'Already Initialized');