mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
refactor(Schedule Trigger Node): Deduplicate the cron interface (#4525)
🎨 deduplicate Cron Interface
This commit is contained in:
parent
bd9bf3cf76
commit
9e457d614c
|
@ -1,7 +0,0 @@
|
|||
export type ICronExpression = [
|
||||
string | Date,
|
||||
string | Date,
|
||||
string | Date,
|
||||
string | Date,
|
||||
string | Date,
|
||||
];
|
|
@ -8,7 +8,6 @@ import {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
import { CronJob } from 'cron';
|
||||
import { ICronExpression } from './CronInterface';
|
||||
import moment from 'moment';
|
||||
|
||||
export class ScheduleTrigger implements INodeType {
|
||||
|
@ -463,7 +462,7 @@ export class ScheduleTrigger implements INodeType {
|
|||
if (interval[i].field === 'hours') {
|
||||
const hour = interval[i].hoursInterval?.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 cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
|
||||
cronJobs.push(cronJob);
|
||||
|
@ -473,7 +472,7 @@ export class ScheduleTrigger implements INodeType {
|
|||
const day = interval[i].daysInterval?.toString() as string;
|
||||
const hour = interval[i].triggerAtHour?.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 cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
|
||||
cronJobs.push(cronJob);
|
||||
|
@ -485,7 +484,7 @@ export class ScheduleTrigger implements INodeType {
|
|||
const week = interval[i].weeksInterval as number;
|
||||
const days = interval[i].triggerAtDay as IDataObject[];
|
||||
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 cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
|
||||
cronJobs.push(cronJob);
|
||||
|
@ -496,7 +495,7 @@ export class ScheduleTrigger implements INodeType {
|
|||
const day = interval[i].triggerAtDayOfMonth?.toString() as string;
|
||||
const hour = interval[i].triggerAtHour?.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 cronJob = new CronJob(cronExpression, executeTrigger, undefined, true, timezone);
|
||||
cronJobs.push(cronJob);
|
||||
|
|
Loading…
Reference in a new issue