简体   繁体   English

服务器关闭后自动重新调度作业

[英]auto reschedule job after server down by quartz

The requirement is simple, say server need to set variable salesOffRatio to 0.8 between 01-01 and 01-10 total ten days. 要求很简单,比如说服务器需要在总共十天的01-01和01-10之间将变量salesOffRatio设置为0.8。 And "salesOffRatio = 0.8" is a job which triggered by a quartz trigger at 01-10 00:00:00. “ salesOffRatio = 0.8”是由石英触发器在01-10 00:00:00触发的作业。 The problem is server restart at 01-05 due to power lack, variable salesOffRatio will be not 0.8 anymore, it will become to init value and the trigger will not fire because 01-10 00:00:00 has been passed. 问题是由于电源不足,服务器将在01-05重新启动,变量salesOffRatio将不再是0.8,它将变为init值,并且触发器不会触发,因为已通过01-10 00:00:00。

Is there a solution to solve this kind problem? 有解决此类问题的解决方案吗? I need auto re-schedule because the job need to set a state for a very long duration and server have to restart in that duration due to maintain operation or something like that which can not be avoid. 我需要自动重新计划,因为作业需要设置很长时间的状态,并且由于维护操作或类似无法避免的事情,服务器必须在该时间内重新启动。

misfire with jdbcJobStore seems ok, set a proper misfire threshold. 使用jdbcJobStore点火失败似乎可以,请设置适当的点火失败阈值。 But it is universal, in this situation, I need to set distinct value for each job ( salesOffRatio1, salesOffRatio2...) 但这是通用的,在这种情况下,我需要为每个作业设置不同的值(salesOffRatio1,salesOffRatio2 ...)

Few solutions I came up with: 我想到的解决方案很少:

  1. Your salesOffRatio should survive server restart. 您的salesOffRatio应该在服务器重启后仍然存在。 Store it in a database, file, whatever. 将其存储在数据库,文件等中。 Instead of modifying the variable, update your database in a job. 无需修改变量,而是在作业中更新数据库。

  2. If your use-case is so simple, why not create a function 如果您的用例是如此简单,为什么不创建一个函数

     double getSalesOffRatio(Date effectiveDate) 

    that will return correct salesOffRatio value depending on effectiveDate passed? 会根据传递的effectiveDate返回正确的salesOffRatio值? In other words just compute salesOffRatio every time you need it. 换句话说,只要您需要,就可以计算salesOffRatio BTW the extra argument will make testing easier compared to reading current system time inside getSalesOffRatio() . 顺便说一句,与在getSalesOffRatio()读取当前系统时间相比,额外的参数将使测试更加容易。

  3. You can use XML scheduling plugin or some other way to reschedule all jobs every time server restarts. 您可以使用XML计划插件或其他任何方式在每次服务器重新启动时重新计划所有作业。 By default job is deleted after it was triggered ( durable property) so by carefully configuring misfire policy, scheduler will refire all your jobs on startup. 默认情况下,作业在被触发后被删除( durable属性),因此通过仔细配置失火策略,调度程序将在启动时重新激发所有作业。 Brittle in my opinion. 我觉得很脆弱。

Final thought: talking about misfire policies, have you considered what will happen if restart occurs when the job was scheduled ? 最后的想法:谈论失火政策,您是否考虑过在计划作业时重新启动会发生什么?

Either you could persist the value of 'salesOffRatio' to a database or a file, and then rather than initialising it to a default value, you could initialise it to the stored value. 您可以将“ salesOffRatio”的值持久保存到数据库或文件中,然后可以将其初始化为存储的值,而不是将其初始化为默认值。

Alternatively you could run a program on startup to re-run all quartz triggers (or just those in the jobgroup which you need for updating these values). 或者,您可以在启动时运行一个程序以重新运行所有的石英触发器(或仅是更新这些值所需的作业组中的触发器)。

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

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