From 0c0c0bda674d3efe7ae922f371f659781bd5f442 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 25 Mar 2021 11:23:54 +0100 Subject: [PATCH] :zap: Some cleanup --- packages/cli/commands/execute.ts | 4 ++-- packages/cli/commands/export/credentials.ts | 2 +- packages/cli/commands/export/workflow.ts | 2 +- packages/cli/commands/start.ts | 19 ++++++++++--------- packages/cli/commands/update/workflow.ts | 2 +- packages/cli/commands/webhook.ts | 12 ++++++------ packages/cli/commands/worker.ts | 4 ++-- packages/cli/src/Server.ts | 2 -- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/cli/commands/execute.ts b/packages/cli/commands/execute.ts index b3450e9ef2..3091778def 100644 --- a/packages/cli/commands/execute.ts +++ b/packages/cli/commands/execute.ts @@ -21,7 +21,7 @@ import { WorkflowCredentials, WorkflowHelpers, WorkflowRunner, -} from "../src"; +} from '../src'; export class Execute extends Command { @@ -127,7 +127,7 @@ export class Execute extends Command { // Check if the workflow contains the required "Start" node // "requiredNodeTypes" are also defined in editor-ui/views/NodeView.vue const requiredNodeTypes = ['n8n-nodes-base.start']; - let startNode: INode | undefined= undefined; + let startNode: INode | undefined = undefined; for (const node of workflowData!.nodes) { if (requiredNodeTypes.includes(node.type)) { startNode = node; diff --git a/packages/cli/commands/export/credentials.ts b/packages/cli/commands/export/credentials.ts index 5175e3be2d..ec12033446 100644 --- a/packages/cli/commands/export/credentials.ts +++ b/packages/cli/commands/export/credentials.ts @@ -140,7 +140,7 @@ export class ExportCredentialsCommand extends Command { let fileContents: string, i: number; for (i = 0; i < credentials.length; i++) { fileContents = JSON.stringify(credentials[i], null, flags.pretty ? 2 : undefined); - const filename = (flags.output!.endsWith(path.sep) ? flags.output! : flags.output + path.sep) + credentials[i].id + ".json"; + const filename = (flags.output!.endsWith(path.sep) ? flags.output! : flags.output + path.sep) + credentials[i].id + '.json'; fs.writeFileSync(filename, fileContents); } console.log('Successfully exported', i, 'credentials.'); diff --git a/packages/cli/commands/export/workflow.ts b/packages/cli/commands/export/workflow.ts index 33066fd380..0cf1d712ad 100644 --- a/packages/cli/commands/export/workflow.ts +++ b/packages/cli/commands/export/workflow.ts @@ -116,7 +116,7 @@ export class ExportWorkflowsCommand extends Command { let fileContents: string, i: number; for (i = 0; i < workflows.length; i++) { fileContents = JSON.stringify(workflows[i], null, flags.pretty ? 2 : undefined); - const filename = (flags.output!.endsWith(path.sep) ? flags.output! : flags.output + path.sep) + workflows[i].id + ".json"; + const filename = (flags.output!.endsWith(path.sep) ? flags.output! : flags.output + path.sep) + workflows[i].id + '.json'; fs.writeFileSync(filename, fileContents); } console.log('Successfully exported', i, 'workflows.'); diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index 36cd9c4547..c01ad0ed4a 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -17,11 +17,12 @@ import { Db, ExternalHooks, GenericHelpers, + IExecutionsCurrentSummary, LoadNodesAndCredentials, NodeTypes, Server, TestWebhooks, -} from "../src"; +} from '../src'; import { IDataObject } from 'n8n-workflow'; @@ -97,7 +98,7 @@ export class Start extends Command { // Wait for active workflow executions to finish const activeExecutionsInstance = ActiveExecutions.getInstance(); - let executingWorkflows = activeExecutionsInstance.getActiveExecutions(); + let executingWorkflows = activeExecutionsInstance.getActiveExecutions() as IExecutionsCurrentSummary[]; let count = 0; while (executingWorkflows.length !== 0) { @@ -132,7 +133,7 @@ export class Start extends Command { await (async () => { try { // Start directly with the init of the database to improve startup time - const startDbInitPromise = Db.init().catch(error => { + const startDbInitPromise = Db.init().catch((error: Error) => { console.error(`There was an error initializing DB: ${error.message}`); processExistCode = 1; @@ -171,7 +172,7 @@ export class Start extends Command { const redisDB = config.get('queue.bull.redis.db'); const redisConnectionTimeoutLimit = config.get('queue.bull.redis.timeoutThreshold'); let lastTimer = 0, cumulativeTimeout = 0; - + const settings = { retryStrategy: (times: number): number | null => { const now = Date.now(); @@ -183,7 +184,7 @@ export class Start extends Command { cumulativeTimeout += now - lastTimer; lastTimer = now; if (cumulativeTimeout > redisConnectionTimeoutLimit) { - console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + ". Exiting process."); + console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + '. Exiting process.'); process.exit(1); } } @@ -203,7 +204,7 @@ export class Start extends Command { if (redisDB) { settings.db = redisDB; } - + // This connection is going to be our heartbeat // IORedis automatically pings redis and tries to reconnect // We will be using the retryStrategy above @@ -218,13 +219,13 @@ export class Start extends Command { } }); } - + const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType; if (dbType === 'sqlite') { const shouldRunVacuum = config.get('database.sqlite.executeVacuumOnStartup') as number; if (shouldRunVacuum) { - Db.collections.Execution!.query("VACUUM;"); + Db.collections.Execution!.query('VACUUM;'); } } @@ -283,7 +284,7 @@ export class Start extends Command { Start.openBrowser(); } this.log(`\nPress "o" to open in Browser.`); - process.stdin.on("data", (key : string) => { + process.stdin.on('data', (key: string) => { if (key === 'o') { Start.openBrowser(); inputText = ''; diff --git a/packages/cli/commands/update/workflow.ts b/packages/cli/commands/update/workflow.ts index 6f9e8de2ff..06be05759d 100644 --- a/packages/cli/commands/update/workflow.ts +++ b/packages/cli/commands/update/workflow.ts @@ -9,7 +9,7 @@ import { import { Db, GenericHelpers, -} from "../../src"; +} from '../../src'; export class UpdateWorkflowCommand extends Command { diff --git a/packages/cli/commands/webhook.ts b/packages/cli/commands/webhook.ts index b17db917bd..68c5876543 100644 --- a/packages/cli/commands/webhook.ts +++ b/packages/cli/commands/webhook.ts @@ -17,7 +17,7 @@ import { NodeTypes, TestWebhooks, WebhookServer, -} from "../src"; +} from '../src'; import { IDataObject } from 'n8n-workflow'; @@ -98,7 +98,7 @@ export class Webhook extends Command { // Wrap that the process does not close but we can still use async await (async () => { if (config.get('executions.mode') !== 'queue') { - /** + /** * It is technically possible to run without queues but * there are 2 known bugs when running in this mode: * - Executions list will be problematic as the main process @@ -154,7 +154,7 @@ export class Webhook extends Command { const redisDB = config.get('queue.bull.redis.db'); const redisConnectionTimeoutLimit = config.get('queue.bull.redis.timeoutThreshold'); let lastTimer = 0, cumulativeTimeout = 0; - + const settings = { retryStrategy: (times: number): number | null => { const now = Date.now(); @@ -166,7 +166,7 @@ export class Webhook extends Command { cumulativeTimeout += now - lastTimer; lastTimer = now; if (cumulativeTimeout > redisConnectionTimeoutLimit) { - console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + ". Exiting process."); + console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + '. Exiting process.'); process.exit(1); } } @@ -186,7 +186,7 @@ export class Webhook extends Command { if (redisDB) { settings.db = redisDB; } - + // This connection is going to be our heartbeat // IORedis automatically pings redis and tries to reconnect // We will be using the retryStrategy above @@ -201,7 +201,7 @@ export class Webhook extends Command { } }); } - + await WebhookServer.start(); // Start to get active workflows and run their triggers diff --git a/packages/cli/commands/worker.ts b/packages/cli/commands/worker.ts index b2b78c4c7a..573014cf62 100644 --- a/packages/cli/commands/worker.ts +++ b/packages/cli/commands/worker.ts @@ -35,7 +35,7 @@ import { ResponseHelper, WorkflowCredentials, WorkflowExecuteAdditionalData, -} from "../src"; +} from '../src'; import * as config from '../config'; import * as Bull from 'bull'; @@ -241,7 +241,7 @@ export class Worker extends Command { cumulativeTimeout += now - lastTimer; lastTimer = now; if (cumulativeTimeout > redisConnectionTimeoutLimit) { - console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + ". Exiting process."); + console.error('Unable to connect to Redis after ' + redisConnectionTimeoutLimit + '. Exiting process.'); process.exit(1); } } diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 2e68824f62..39fb76cc18 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -92,9 +92,7 @@ import { import { FindManyOptions, FindOneOptions, - LessThan, LessThanOrEqual, - MoreThanOrEqual, Not, } from 'typeorm';