refactor(core): Centralize CronJob management (#10033)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-07-16 20:42:48 +02:00
committed by GitHub
parent 36b314d031
commit 09f2cf9eaf
18 changed files with 730 additions and 429 deletions

View File

@@ -7,8 +7,6 @@ import type {
} from 'n8n-workflow';
import { NodeHelpers, toCronExpression } from 'n8n-workflow';
import { CronJob } from 'cron';
export class Cron implements INodeType {
description: INodeTypeDescription = {
displayName: 'Cron',
@@ -66,27 +64,11 @@ export class Cron implements INodeType {
this.emit([this.helpers.returnJsonArray([{}])]);
};
const timezone = this.getTimezone();
// Start the cron-jobs
const cronJobs = cronTimes.map(
(cronTime) => new CronJob(cronTime, executeTrigger, undefined, true, timezone),
);
// Stop the cron-jobs
async function closeFunction() {
for (const cronJob of cronJobs) {
cronJob.stop();
}
}
async function manualTriggerFunction() {
executeTrigger();
}
// Register the cron-jobs
cronTimes.forEach((cronTime) => this.helpers.registerCron(cronTime, executeTrigger));
return {
closeFunction,
manualTriggerFunction,
manualTriggerFunction: async () => executeTrigger(),
};
}
}