mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
fix(core): Scheduler tasks should not trigger on follower instances (#10507)
This commit is contained in:
committed by
GitHub
parent
c8ab9b1f84
commit
3428f28a73
@@ -1,13 +1,24 @@
|
||||
import { Service } from 'typedi';
|
||||
import { CronJob } from 'cron';
|
||||
import type { CronExpression, Workflow } from 'n8n-workflow';
|
||||
import { InstanceSettings } from './InstanceSettings';
|
||||
|
||||
@Service()
|
||||
export class ScheduledTaskManager {
|
||||
constructor(private readonly instanceSettings: InstanceSettings) {}
|
||||
|
||||
readonly cronJobs = new Map<string, CronJob[]>();
|
||||
|
||||
registerCron(workflow: Workflow, cronExpression: CronExpression, onTick: () => void) {
|
||||
const cronJob = new CronJob(cronExpression, onTick, undefined, true, workflow.timezone);
|
||||
const cronJob = new CronJob(
|
||||
cronExpression,
|
||||
() => {
|
||||
if (this.instanceSettings.isLeader) onTick();
|
||||
},
|
||||
undefined,
|
||||
true,
|
||||
workflow.timezone,
|
||||
);
|
||||
const cronJobsForWorkflow = this.cronJobs.get(workflow.id);
|
||||
if (cronJobsForWorkflow) {
|
||||
cronJobsForWorkflow.push(cronJob);
|
||||
|
||||
Reference in New Issue
Block a user