Coreoz / Wisp

A simple Java Scheduler library with a minimal footprint and a straightforward API
Apache License 2.0
133 stars 23 forks source link

Run schedule once on Instant #6

Closed carbotaniuman closed 5 years ago

carbotaniuman commented 5 years ago

I have an Instant class and I want to run a job based on this. Is this possible?

amanteaux commented 5 years ago

Hum I am not sure I am following you. An Instant represent a single point in time. Do you want to run a job only once in the future? If so you can create your Schedule with: Schedules.executeOnce(Schedules.executeAt("05:30")) And if you really want to pass an instant as a parameter you can do something like that: Schedules.executeOnce(new FixedDelaySchedule(Duration.between(Instant.now(), yourInstant)))

carbotaniuman commented 5 years ago

@amanteaux That's exactly what I mean. Does the second line of code have any pitfalls or gotchas?

amanteaux commented 5 years ago

@carbotaniuman no I do not see any pitfalls or gotchas. Also do not hesitate to directly create your own Schedule. In your case you can do something like this: Schedules.executeOnce((c, e, l) -> yourInstant.getEpochSecond() * 1000);. You can have a look at the Schedule interface for details: https://github.com/Coreoz/Wisp/blob/master/src/main/java/com/coreoz/wisp/schedule/Schedule.java