【问题标题】:Scheduler in Kubernetes runs twice in node applicationScheduler in Kubernetes runs twice in node application
【发布时间】:2022-11-09 12:15:36
【问题描述】:

I have an node application running in Kubernetes scheduled a job in node scheduler to run every day by midnight, but scheduler is running twice a day.

Kubernetes
Version - 1.21.5
Node - 13.0
Server
I have two nodes with an load balancer.

Update1

var scheduler = require('node-schedule');
function getRule() {
    var rule = new scheduler.RecurrenceRule();
    // rule.minute = new scheduler.Range(0, 59, 59);
    rule.hour = 23;
    rule.minute = 45;
    return rule;
}

exports.createSchedule = function () {
    var rule = getRule();
    scheduler.scheduleJob(rule, send1DayActivationReminderEmail);
};

This same set of code works in Heroku application, which runs only once.

  • could you please share some config or your job and cronjob that you are using ?
  • @HarshManvar Updated with config
  • how you are running this code in k8s could you please yaml config of job ?
  • I am running scheduler via node application, while starting node application, the above scheduler schedules the job.

标签: node.js kubernetes digital-ocean scheduler


【解决方案1】:

I have two nodes with an load balancer

Every instance of the application will run this job, there is no way for them to know about each other. So if you run two Pods you will get two executions. One solution is to scale the application to just one instance as I guess was the case with the Heroku deployment. Another solution is to instead trigger the job using a kubernetes cronjob https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/.

  • Thanks for the suggestion cronjob in kubernetes. Many i know every instance of the application will run this job, can you elaborate this one.
  • In every place you run this application this job will trigger. If you run it on two servers the job will run in both places.
  • Thanks, but some day it triggers one time, when I changed container image to new one, it triggers again twice.
【解决方案2】:

When I ran the scheduler without the RecurrenceRule, it runs ones a day, Thanks for the help.

scheduler.scheduleJob('45 23 * * *', send1DayActivationReminderEmail);
    猜你喜欢
    • 2022-12-02
    • 1970-01-01
    • 2018-09-10
    • 2020-02-18
    • 1970-01-01
    • 2022-10-14
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多