使用 Quartz 跨多个无状态应用程序服务器调度单个作业
我在负载均衡器后面有一层相同的应用程序服务器。出于操作原因,我有一个限制,即两个应用程序服务器上的应用程序配置必须相同,以便可以轻松添加和删除节点。所有应用程序服务器共享相同的数据库。应用程序服务器不会/不会集群。
到目前为止,这一直运行良好,但现在我希望有一个在其中一个应用程序服务器上执行的预定作业。所有应用程序服务器都将运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您认为这对您有用吗?
http://www.quartz-scheduler.org/documentation /quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html
摘自链接
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