简体   繁体   English

在Java Scheduler Quartz Cron中设置多个时区

[英]Setting multiple timezones in Java Scheduler Quartz Cron

I need to run a CRON at midnight which auto-assigns some periodic tasks for the people working in my company. 我需要在午夜运行一个CRON,它会为在我公司工作的人自动分配一些定期任务。 The situation I am facing is that my company basically has offices all around US, which has more than 1 timezone. 我面临的情况是我的公司基本上在美国各地设有办事处,有超过1个时区。 So basically I would want the job to be done timezone-specific. 所以基本上我希望这项工作能够按时区进行。 Also, my server is running by UTC. 此外,我的服务器由UTC运行。

If I set EDT as the base timezone (which is 4 hours behind UTC) and set the CRON to be triggered at midnight, the CRON time would be 如果我将EDT设置为基准时区(比UTC晚4小时)并将CRON设置为在午夜触发,则CRON时间将为

0 0 4 * * ? 0 0 4 * *?

The possible way that I think can be is that instead of setting it just once, I set it to be triggered 7 times at the following times: 我认为可能的方式是,不是只设置一次,而是将其设置为在以下时间触发7次:

0 0 4 * * ? [EDT]
0 0 5 * * ? [CDT]
0 0 6 * * ? [MDT]
0 0 7 * * ? [PDT]
0 0 8 * * ? [AKDT]
0 0 9 * * ? [HADT]
0 0 10 * * ? [HST]

So once any of it triggers, it would check which of my offices come under this time zone and will do the job. 因此,一旦它触发,它将检查我的哪个办公室属于这个时区并将完成这项工作。

This may work, as I believe, but does anyone else have any other option instead of this? 我认为,这可能有用,但是否有其他人有其他选择而不是这个? Also, I would need to fix for the Daylight saving, which I am not really sure about how I would want to do. 此外,我需要修复夏令时,我不确定我想怎么做。

I think the simplest approach would probably be to have a single job which ran once an hour, which then went through all the offices, and found any that were now on a later day to the one when the job last ran. 我认为最简单的方法可能就是让一份工作每小时运行一次,然后通过所有的办公室,然后发现现在的任何工作都是在工作最后一次运行的那一天。 (You'd need to maintain that, of course, along with the office's time zone.) That would take care of the DST issue for you, and also cope with a situation when the scheduler went down for a while - the next time it came up, it would "catch up" for all the offices it had missed. (当然,你需要保持这一点,以及办公室的时区。)这会照顾你的DST问题,并且还应对调度程序停机一段时间的情况 - 下次它上来了,它会“赶上”它所错过的所有办公室。

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

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