From 397132688ea16d7e2960f9e47736212b0ffcb660 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Mon, 14 Sep 2020 12:30:58 +0200 Subject: [PATCH] :zap: Wait for active workflow to finish before shutting down --- packages/cli/commands/start.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index ef9170a92..400b9043e 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -8,12 +8,14 @@ const open = require('open'); import * as config from '../config'; import { + ActiveExecutions, ActiveWorkflowRunner, CredentialTypes, CredentialsOverwrites, Db, ExternalHooks, GenericHelpers, + IExecutionsCurrentSummary, LoadNodesAndCredentials, NodeTypes, Server, @@ -85,6 +87,21 @@ export class Start extends Command { await Promise.all(removePromises); + // Wait for active workflow executions to finish + const activeExecutionsInstance = ActiveExecutions.getInstance(); + let executingWorkflows = activeExecutionsInstance.getActiveExecutions(); + + let count = 0; + while (executingWorkflows.length !== 0) { + if (count++ % 4 === 0) { + console.log(`Waiting for ${executingWorkflows.length} active executions to finish...`); + } + await new Promise((resolve) => { + setTimeout(resolve, 500); + }); + executingWorkflows = activeExecutionsInstance.getActiveExecutions(); + } + process.exit(processExistCode); }