问题
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