Kubernetes 中的调度程序在节点应用程序中运行两次

发布于 2025-01-15 22:23:07 字数 723 浏览 2 评论 0原文

我有一个在 Kubernetes 中运行的节点应用程序,在 节点调度程序 中安排了一个每天运行的作业到午夜,但调度程序每天运行两次。

Kubernetes
版本 - 1.21.5
节点 - 13.0
服务器
我有两个带有负载均衡器的节点。

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);
};

这组相同的代码在 Heroku 应用程序中工作,仅运行一次。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知在何时 2025-01-22 22:23:07

我有两个带有负载均衡器的节点

应用程序的每个实例都将运行此作业,它们无法相互了解。因此,如果您运行两个 Pod,您将获得两次执行。一种解决方案是将应用程序扩展到只有一个实例,我猜想 Heroku 部署就是这种情况。另一个解决方案是使用 kubernetes cronjob https://kubernetes 触发作业.io/docs/concepts/workloads/controllers/cron-jobs/

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/.

上课铃就是安魂曲 2025-01-22 22:23:07

当我在没有 RecurrenceRule 的情况下运行调度程序时,它每天运行一个,感谢您的帮助。

scheduler.scheduleJob('45 23 * * *', send1DayActivationReminderEmail);

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

scheduler.scheduleJob('45 23 * * *', send1DayActivationReminderEmail);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文