Make it possible to trigger all X minutes/hours

This commit is contained in:
Jan Oberhauser 2019-12-31 17:41:47 -06:00
parent 2f56561bff
commit 8f25303928
3 changed files with 120 additions and 8 deletions

View file

@ -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) {

View file

@ -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:<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>',
},
{
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) {

View file

@ -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:<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>',
},
{
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.',
},
],
},
],