refactor(Schedule Trigger Node): Deduplicate the cron interface (#4525)

🎨 deduplicate Cron Interface
This commit is contained in:
agobrech 2022-11-10 17:19:13 +01:00 committed by GitHub
parent bd9bf3cf76
commit 9e457d614c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View file

@ -1,7 +0,0 @@
export type ICronExpression = [
string | Date,
string | Date,
string | Date,
string | Date,
string | Date,
];

View file

@ -8,7 +8,6 @@ import {
} from 'n8n-workflow'; } from 'n8n-workflow';
import { CronJob } from 'cron'; import { CronJob } from 'cron';
import { ICronExpression } from './CronInterface';
import moment from 'moment'; import moment from 'moment';
export class ScheduleTrigger implements INodeType { export class ScheduleTrigger implements INodeType {
@ -463,7 +462,7 @@ export class ScheduleTrigger implements INodeType {
if (interval[i].field === 'hours') { if (interval[i].field === 'hours') {
const hour = interval[i].hoursInterval?.toString() as string; const hour = interval[i].hoursInterval?.toString() as string;
const minute = interval[i].triggerAtMinute?.toString() as string; const minute = interval[i].triggerAtMinute?.toString() as string;
const cronTimes: ICronExpression = [minute, `*/${hour}`, '*', '*', '*']; const cronTimes: string[] = [minute, `*/${hour}`, '*', '*', '*'];
const cronExpression: string = cronTimes.join(' '); const cronExpression: string = cronTimes.join(' ');
const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone); const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
cronJobs.push(cronJob); cronJobs.push(cronJob);
@ -473,7 +472,7 @@ export class ScheduleTrigger implements INodeType {
const day = interval[i].daysInterval?.toString() as string; const day = interval[i].daysInterval?.toString() as string;
const hour = interval[i].triggerAtHour?.toString() as string; const hour = interval[i].triggerAtHour?.toString() as string;
const minute = interval[i].triggerAtMinute?.toString() as string; const minute = interval[i].triggerAtMinute?.toString() as string;
const cronTimes: ICronExpression = [minute, hour, `*/${day}`, '*', '*']; const cronTimes: string[] = [minute, hour, `*/${day}`, '*', '*'];
const cronExpression: string = cronTimes.join(' '); const cronExpression: string = cronTimes.join(' ');
const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone); const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
cronJobs.push(cronJob); cronJobs.push(cronJob);
@ -485,7 +484,7 @@ export class ScheduleTrigger implements INodeType {
const week = interval[i].weeksInterval as number; const week = interval[i].weeksInterval as number;
const days = interval[i].triggerAtDay as IDataObject[]; const days = interval[i].triggerAtDay as IDataObject[];
const day = days.length === 0 ? '*' : (days.join(',') as string); const day = days.length === 0 ? '*' : (days.join(',') as string);
const cronTimes: ICronExpression = [minute, hour, `*/${week * 7}`, '*', day]; const cronTimes: string[] = [minute, hour, `*/${week * 7}`, '*', day];
const cronExpression = cronTimes.join(' '); const cronExpression = cronTimes.join(' ');
const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone); const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
cronJobs.push(cronJob); cronJobs.push(cronJob);
@ -496,7 +495,7 @@ export class ScheduleTrigger implements INodeType {
const day = interval[i].triggerAtDayOfMonth?.toString() as string; const day = interval[i].triggerAtDayOfMonth?.toString() as string;
const hour = interval[i].triggerAtHour?.toString() as string; const hour = interval[i].triggerAtHour?.toString() as string;
const minute = interval[i].triggerAtMinute?.toString() as string; const minute = interval[i].triggerAtMinute?.toString() as string;
const cronTimes: ICronExpression = [minute, hour, day, `*/${month}`, '*']; const cronTimes: string[] = [minute, hour, day, `*/${month}`, '*'];
const cronExpression: string = cronTimes.join(' '); const cronExpression: string = cronTimes.join(' ');
const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone); const cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
cronJobs.push(cronJob); cronJobs.push(cronJob);