How to fire akka scheduler daily for a particular time?

半城伤御伤魂 提交于 2019-12-11 01:09:45

问题


I created a Akka's scheduler to send mails daily by a fixed time ( example 6:00 Am daily ). So how to call the actor ? I mean what the logic should i use ? Thank you.


回答1:


Just calculate the difference between now and the following 6PM, put that as the initial delay and then repeat every 24h?




回答2:


Starting the job at 6 AM and simply repeating with 24 hour interval won't work if the server works in time zone observing dst - for half of the year the job will fire either at 5 AM or at 7 AM, depending on when it was initially scheduled.

The OP seems to live in India (which does not observe DST), however to make the solution completely portable (and since he mentions quartz-scheduler), using Quartz and CRON trigger seems safer:

Trigger trigger = newTrigger()
  .withIdentity("trigger3", "group1")
  .startNow()
  .withSchedule(dailyAtHourAndMinute(6, 0))
  .build();

Also Quartz is way more powerful. The only problem is with obtaining the target actor. Probably placing ActorRef in scheduler context and retrieving it in a job is the easiest way.



来源:https://stackoverflow.com/questions/10240627/how-to-fire-akka-scheduler-daily-for-a-particular-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!