From 8f253039280bb5cef7e6db6315c9d31738f168dd Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Tue, 31 Dec 2019 17:41:47 -0600 Subject: [PATCH] :sparkles: Make it possible to trigger all X minutes/hours --- packages/core/src/ActiveWorkflows.ts | 8 +++ packages/nodes-base/nodes/Cron.node.ts | 72 +++++++++++++++++++++++--- packages/workflow/src/NodeHelpers.ts | 48 +++++++++++++++++ 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/packages/core/src/ActiveWorkflows.ts b/packages/core/src/ActiveWorkflows.ts index 9cd4f0079a..8ae57291d4 100644 --- a/packages/core/src/ActiveWorkflows.ts +++ b/packages/core/src/ActiveWorkflows.ts @@ -134,6 +134,14 @@ export class ActiveWorkflows { cronTimes.push(`${Math.floor(Math.random() * 60).toString()} * * * * *`); continue; } + if (item.mode === 'everyX') { + if (item.unit === 'minutes') { + cronTimes.push(`${Math.floor(Math.random() * 60).toString()} */${item.value} * * * *`); + } else if (item.unit === 'hours') { + cronTimes.push(`${Math.floor(Math.random() * 60).toString()} 0 */${item.value} * * *`); + } + continue; + } for (parameterName of parameterOrder) { if (item[parameterName] !== undefined) { diff --git a/packages/nodes-base/nodes/Cron.node.ts b/packages/nodes-base/nodes/Cron.node.ts index 90ad6214ce..7f91b401ee 100644 --- a/packages/nodes-base/nodes/Cron.node.ts +++ b/packages/nodes-base/nodes/Cron.node.ts @@ -55,27 +55,31 @@ export class Cron implements INodeType { options: [ { name: 'Every Minute', - value: 'everyMinute' + value: 'everyMinute', }, { name: 'Every Hour', - value: 'everyHour' + value: 'everyHour', }, { name: 'Every Day', - value: 'everyDay' + value: 'everyDay', }, { name: 'Every Week', - value: 'everyWeek' + value: 'everyWeek', }, { name: 'Every Month', - value: 'everyMonth' + value: 'everyMonth', + }, + { + name: 'Every X', + value: 'everyX', }, { name: 'Custom', - value: 'custom' + value: 'custom', }, ], default: 'everyDay', @@ -94,7 +98,8 @@ export class Cron implements INodeType { mode: [ 'custom', 'everyHour', - 'everyMinute' + 'everyMinute', + 'everyX', ], }, }, @@ -113,7 +118,8 @@ export class Cron implements INodeType { hide: { mode: [ 'custom', - 'everyMinute' + 'everyMinute', + 'everyX', ], }, }, @@ -196,6 +202,48 @@ export class Cron implements INodeType { default: '* * * * * *', description: 'Use custom cron expression. Values and ranges as follows:', }, + { + displayName: 'Value', + name: 'value', + type: 'number', + typeOptions: { + minValue: 0, + maxValue: 1000, + }, + displayOptions: { + show: { + mode: [ + 'everyX', + ], + }, + }, + default: 2, + description: 'All how many X minutes/hours it should trigger.', + }, + { + displayName: 'Unit', + name: 'unit', + type: 'options', + displayOptions: { + show: { + mode: [ + 'everyX', + ], + }, + }, + options: [ + { + name: 'Minutes', + value: 'minutes' + }, + { + name: 'Hours', + value: 'hours' + }, + ], + default: 'hours', + description: 'If it should trigger all X minutes or hours.', + }, ] }, ], @@ -236,6 +284,14 @@ export class Cron implements INodeType { cronTimes.push(`${Math.floor(Math.random() * 60).toString()} * * * * *`); continue; } + if (item.mode === 'everyX') { + if (item.unit === 'minutes') { + cronTimes.push(`${Math.floor(Math.random() * 60).toString()} */${item.value} * * * *`); + } else if (item.unit === 'hours') { + cronTimes.push(`${Math.floor(Math.random() * 60).toString()} 0 */${item.value} * * *`); + } + continue; + } for (parameterName of parameterOrder) { if (item[parameterName] !== undefined) { diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index d398be8394..a1b631a19f 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -77,6 +77,10 @@ export function getSpecialNodeParameters(nodeType: INodeType) { name: 'Every Month', value: 'everyMonth', }, + { + name: 'Every X', + value: 'everyX', + }, { name: 'Custom', value: 'custom', @@ -99,6 +103,7 @@ export function getSpecialNodeParameters(nodeType: INodeType) { 'custom', 'everyHour', 'everyMinute', + 'everyX', ], }, }, @@ -118,6 +123,7 @@ export function getSpecialNodeParameters(nodeType: INodeType) { mode: [ 'custom', 'everyMinute', + 'everyX', ], }, }, @@ -200,6 +206,48 @@ export function getSpecialNodeParameters(nodeType: INodeType) { default: '* * * * * *', description: 'Use custom cron expression. Values and ranges as follows:', }, + { + displayName: 'Value', + name: 'value', + type: 'number', + typeOptions: { + minValue: 0, + maxValue: 1000, + }, + displayOptions: { + show: { + mode: [ + 'everyX', + ], + }, + }, + default: 2, + description: 'All how many X minutes/hours it should trigger.', + }, + { + displayName: 'Unit', + name: 'unit', + type: 'options', + displayOptions: { + show: { + mode: [ + 'everyX', + ], + }, + }, + options: [ + { + name: 'Minutes', + value: 'minutes' + }, + { + name: 'Hours', + value: 'hours' + }, + ], + default: 'hours', + description: 'If it should trigger all X minutes or hours.', + }, ], }, ],