简体   繁体   English

使用Quartz在多个无状态应用服务器上安排单个作业

[英]Using Quartz to Schedule Single Job Across Multiple Stateless App Servers

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. 所有应用服务器都将运行Quartz并具有相同的运行作业计划。 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? a)我可以将此行为挂钩到Quartz中,以便不必在每个作业的基础上完成吗? Ie 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? b)Quartz是否提供任何内置机制来实现类似于上面的内容,所以我不必自己滚动它?

Thanks! 谢谢!

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 http://www.quartz-scheduler.org/documentation/quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html链接摘录

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. 群集当前仅适用于JDBC-Jobstore(JobStoreTX或JobStoreCMT),并且基本上通过使群集的每个节点共享同一数据库来工作。

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.` 当触发器的触发时间发生时,获取它的第一个节点(通过锁定它)是将触发它的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM