Make it possible to use custom cron-expressions and add

"Every Hour" option to Cron-Node
This commit is contained in:
Jan Oberhauser 2019-07-11 08:00:57 +02:00
parent cc3f2c42d1
commit 60162d5c46

View file

@ -53,6 +53,10 @@ export class Cron implements INodeType {
name: 'mode', name: 'mode',
type: 'options', type: 'options',
options: [ options: [
{
name: 'Every Hour',
value: 'everyHour'
},
{ {
name: 'Every Day', name: 'Every Day',
value: 'everyDay' value: 'everyDay'
@ -65,6 +69,10 @@ export class Cron implements INodeType {
name: 'Every Month', name: 'Every Month',
value: 'everyMonth' value: 'everyMonth'
}, },
{
name: 'Custom',
value: 'custom'
},
], ],
default: 'everyDay', default: 'everyDay',
description: 'How often to trigger.', description: 'How often to trigger.',
@ -77,6 +85,14 @@ export class Cron implements INodeType {
minValue: 0, minValue: 0,
maxValue: 23, maxValue: 23,
}, },
displayOptions: {
hide: {
mode: [
'custom',
'everyHour',
],
},
},
default: 14, default: 14,
description: 'The hour of the day to trigger (24h format).', description: 'The hour of the day to trigger (24h format).',
}, },
@ -88,6 +104,13 @@ export class Cron implements INodeType {
minValue: 0, minValue: 0,
maxValue: 59, maxValue: 59,
}, },
displayOptions: {
hide: {
mode: [
'custom',
],
},
},
default: 0, default: 0,
description: 'The minute of the day to trigger.', description: 'The minute of the day to trigger.',
}, },
@ -153,6 +176,20 @@ export class Cron implements INodeType {
default: '1', default: '1',
description: 'The weekday to trigger.', description: 'The weekday to trigger.',
}, },
{
displayName: 'Cron Expression',
name: 'cronExpression',
type: 'string',
displayOptions: {
show: {
mode: [
'custom',
],
},
},
default: '* * * * * *',
description: 'Use custom cron expression. Values and ranges as follows:<ul><li>Seconds: 0-59</li><li>Minutes: 0 - 59</li><li>Hours: 0 - 23</li><li>Day of Month: 1 - 31</li><li>Months: 0 - 11 (Jan - Dec)</li><li>Day of Week: 0 - 6 (Sun - Sat)</li></ul>',
},
] ]
}, },
], ],
@ -185,6 +222,11 @@ export class Cron implements INodeType {
if (triggerTimes.item !== undefined) { if (triggerTimes.item !== undefined) {
for (const item of triggerTimes.item) { for (const item of triggerTimes.item) {
cronTime = []; cronTime = [];
if (item.mode === 'custom') {
cronTimes.push(item.cronExpression as string);
continue;
}
for (parameterName of parameterOrder) { for (parameterName of parameterOrder) {
if (item[parameterName] !== undefined) { if (item[parameterName] !== undefined) {
// Value is set so use it // Value is set so use it