使用 Quartz 跨多个无状态应用程序服务器调度单个作业

发布于 2024-11-19 12:28:46 字数 670 浏览 0 评论 0原文

我在负载均衡器后面有一层相同的应用程序服务器。出于操作原因,我有一个限制,即两个应用程序服务器上的应用程序配置必须相同,以便可以轻松添加和删除节点。所有应用程序服务器共享相同的数据库。应用程序服务器不会/不会集群。

到目前为止,这一直运行良好,但现在我希望有一个在其中一个应用程序服务器上执行的预定作业。所有应用程序服务器都将运行 Quartz 并具有相同的运行作业时间表。触发器将在每个应用程序服务器上触发,但我希望只有一个应用程序服务器实际执行该作业 - 本质上它们都竞相启动,并且只有一个实际启动,其余的应用程序服务器只是忽略该作业。这里的想法是,如果我们丢失一个应用程序服务器,另一台应用程序服务器将代替运行该作业,如果我们添加新的应用程序服务器,它们将轮流运行作业。

我计划通过在数据库中建立一个“作业锁定”表来实现此目的,所有应用程序服务器都会在开始作业之前读取该表,并且仅在作业“解锁”时才启动。首先对表进行更新的应用服务器实际上会通过将表更新为运行状态/在作业结束时重置它来阻止其他服务器。

在构建这个之前,我希望那些对 Quartz 有更多经验的人提供一些意见:

a) 我可以将此行为挂接到 Quartz 中,这样就不必在每个作业的基础上完成吗?即,开发人员可以添加新作业,而不必担心作业锁定,因为它被抽象了。

b) Quartz 是否提供任何内置机制来实现与上面类似的功能,这样我就不必自己动手了?

谢谢!

I have a layer of identical app servers behind a load balancer. For operational reasons I have the constraint that the application configuration on both app servers must be identical so that nodes can easily be added and removed. All app servers share the same database. App servers are not/will not be clustered.

This has worked fine until now, but now I would like to have a scheduled job that executes on exactly one of the app servers. All app servers will run Quartz and have the same schedule for running jobs. The trigger will fire on every app server, but I would like only one app server to actually execute the job - essentially they all race to start and only one actually starts, the remaining app servers just ignore the job. The idea here is that if we lose an app server, another one would run the job instead, and if we add new app servers, they will take their turn at running jobs.

I was planning to do this by having a 'job lock' table in the database that all app servers would read prior to starting a job and only start if job is 'unlocked'. The app server that makes the update first to the table will essentially block others by updating the table to a running state/resetting it at the end of the job.

Before I build this, I'd appreciate some input from those with more experience of Quartz:

a) Can I hook this behaviour into Quartz so that it doesn't have to be done on a per job basis? I.e. developers can add new jobs without worrying about job locking as it is abstracted away.

b) Does Quartz provide any built in mechanisms to achieve something similar to above so I don't have to roll it myself?

Thanks!

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

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

发布评论

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

评论(1

农村范ル 2024-11-26 12:28:46

您认为这对您有用吗?
http://www.quartz-scheduler.org/documentation /quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html
摘自链接

集群目前仅适用于 JDBC-Jobstore(JobStoreTX 或 JobStoreCMT),并且本质上是通过让集群的每个节点共享相同的数据库来工作的。

负载平衡会自动发生,集群的每个节点都会尽快触发作业。当触发器的触发时间发生时,第一个获取它的节点(通过在其上放置锁)是将触发它的节点。`

Do you think this will work for you?
http://www.quartz-scheduler.org/documentation/quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html
Excerpt from the link

Clustering currently only works with the JDBC-Jobstore (JobStoreTX or JobStoreCMT), and essentially works by having each node of the cluster share the same database.

Load-balancing occurs automatically, with each node of the cluster firing jobs as quickly as it can. When a trigger's firing time occurs, the first node to acquire it (by placing a lock on it) is the node that will fire it.`

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