A module to implement scheduling on top of Vertx timers.
Initially this includes a weekly schedule with configurable behavior on DST changes.
...
dependencies {
...
compile "com.sendgrid.labs:vertx-scheduler:$schedulerVersion"
}
repositories {
mavenCentral()
}
...
Scheduler scheduler = Scheduler.create(vertx);
// Tuesday at 2:30 AM UTC
TimeOfWeek time1 = TimeOfWeek.create(Day.TUE, 2, 30, 0, 0);
// Tuesday at 2:30 AM localtime
TimeOfWeek time2 = TimeOfWeek.create(TimeZone.getTimeZone("America/New_York"), Day.TUE, 2, 30, 0, 0);
// Sunday at 01:01 AM UTC
TimeOfWeek time3 = TimeOfWeek.create(60*60*1000 + 60*1000);
// Sunday at 01:01 AM localtime
TimeOfWeek time4 = TimeOfWeek.create(TimeZone.getTimeZone("America/New_York"), 60*60*1000 + 60*1000);
Timer timer1 = scheduler.setTimer(time1, new Handler<Timer>() {
public void handle(Timer t) {
// ...
}
});
Timer timer2 = scheduler.setPeriodic(time2, new Handler<Timer>() {
public void handle(Timer t) {
// ...
}
});
scheduler.cancelTimer(timer1);
Behavior on DST changes is configurable. Default is to skip when time changes ahead and to run both when time changes back.
TimeOfWeek time1 = TimeOfWeek.create(TimeZone.getTime("America/New_York", Day.TUE, 2, 30, 0, 0, DstAheadBehavior.DST_AHEAD_SKIP, DstBackBehavior.DST_BACK_BOTH_HOURS);
The scheduler can either skip any events during the missing hour (DST_AHEAD_SKIP), or run them on the next hour (DST_AHEAD_NEXT_HOUR).
The scheduler can callback on the first occurrence of the duplicated hour (DST_BACK_FIRST_HOUR), just the second (DST_BACK_SECOND_HOUR), or both (DST_BACK_BOTH_HOURS).
scheduler.stop();