java - Play Framework/Akka scheduler delay drift -
i have play 2.3 project need schedule action 1 time every whole hour, utilize akka schedule in global.onstart. action takes far less 1 hr finish (it checks database potential updates, executes handful of web requests based on them).
however, every time action runs except first, delayed 1 second. after 60 hours/updates, it's delayed whole minute, , presumably after 9 months delayed whole hour.
at first tried setting frequency (60 * 60) - 1 seconds, , worked @ first, it's offset anyway , ends running late.
it seems frequency doesn't start counting downwards (so speak) until action complete, results in delay, can do prevent drift?
here's code have calculate delays , schedule action:
// time until next total hr static public finiteduration getdelay() { calendar currentcalendar = calendar.getinstance(); long min = currentcalendar.get(calendar.minute); long sec = currentcalendar.get(calendar.second); long ms = currentcalendar.get(calendar.millisecond); min = (60l - minute) * 60 * 1000; sec = (60 - second) * 1000; ms = 1000l - ms; long delay = min + sec + ms; homecoming finiteduration.create(delay, timeunit.milliseconds); } // update 1 time every 60 minutes static public finiteduration getfrequency() { homecoming finiteduration.create(60, timeunit.minutes); } akka.system().scheduler() .schedule(getdelay(), getfrequency(), publisher.makerunnable(), akka.system().dispatcher());
the akka scheduler not purport accurate in scheduling maintains queue of jobs checks on each "tick" (see warning on this page ). if want have accurate timing of jobs, suggest utilize cron-like library such quartz can issue messages @ right time. allows more exactly schedule jobs according wall clock time rely on akka's notion of "tick".
java playframework-2.0 akka playframework-2.3
No comments:
Post a Comment