Last active
February 12, 2017 22:47
-
-
Save alexandru/7f7d80e7e70e2d58c9d02b9cdc5f5a2a to your computer and use it in GitHub Desktop.
Revisions
-
alexandru revised this gist
Feb 1, 2017 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,7 @@ def scheduleOncePerDay(time: LocalTime, now: DateTime = DateTime.now())(cb: () = if (next.compareTo(now) <= 0) next.plusDays(1).getMillis else next.getMillis } s.scheduleOnce(nextTick - now.getMillis, TimeUnit.MILLISECONDS, new Runnable { def run(): Unit = { try cb() catch { -
alexandru revised this gist
Feb 1, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,12 @@ import scala.util.control.NonFatal def scheduleOncePerDay(time: LocalTime, now: DateTime = DateTime.now())(cb: () => Unit) (implicit s: Scheduler): Cancelable = { val nextTick = { val next = now.toDateTime(DateTimeZone.UTC).withTime(time) if (next.compareTo(now) <= 0) next.plusDays(1).getMillis else next.getMillis } val delay = nextTick - now.getMillis s.scheduleOnce(remainingMs, TimeUnit.MILLISECONDS, new Runnable { -
alexandru created this gist
Feb 1, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import org.joda.time._ import monix.execution._ import monix.execution.Scheduler.Implicits.global import java.util.concurrent.TimeUnit import scala.util.control.NonFatal def scheduleOncePerDay(time: LocalTime, now: DateTime = DateTime.now())(cb: () => Unit) (implicit s: Scheduler): Cancelable = { val remainingMs = now.getMillis - { val next = now.toDateTime(DateTimeZone.UTC).withTime(time) if (next.compareTo(now) <= 0) next.plusDays(1).getMillis else next.getMillis } s.scheduleOnce(remainingMs, TimeUnit.MILLISECONDS, new Runnable { def run(): Unit = { try cb() catch { case NonFatal(ex) => s.reportFailure(ex) } // Next please! scheduleOncePerDay(time)(cb)(s) } }) }