Class Schedule
java.lang.Object
org.jobrunr.scheduling.Schedule
- All Implemented Interfaces:
Comparable<Schedule>
- Direct Known Subclasses:
CronExpression, CustomSchedule, Interval, ScheduleWrapper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasString()Returns the string representation of the schedule.intCompare twoScheduleobjects based on next occurrence.final DurationCalculates the duration between two consecutive scheduled executions.booleaninthashCode()booleanbooleanbooleanDetermines whether this schedule triggers more frequently than once per minute.abstract InstantCalculates the next occurrence based on the creation time and the provided base time.A human-readable string of thisSchedule.toString()voidvalidate()
-
Field Details
-
carbonAwareScheduleMargin
-
-
Constructor Details
-
Schedule
protected Schedule() -
Schedule
-
-
Method Details
-
next
@VisibleFor("testing") public abstract Instant next(Instant createdAtInstant, Instant currentInstant, ZoneId zoneId) Calculates the next occurrence based on the creation time and the provided base time.- Parameters:
createdAtInstant- Instant object when the schedule was first createdcurrentInstant- Instant object used to calculate the next occurrence (normally Instant.now()).zoneId- the zone for which to calculate the schedule- Returns:
- Instant of the next occurrence.
-
asString
Returns the string representation of the schedule. The Schedule must be convertible back and from the String.- Returns:
- the string representation of the schedule.
-
toHumanReadableString
A human-readable string of thisSchedule. This value is displayed as the schedule expression on the Dashboard.Note that the returned value must not be null.
Use case
It's particularly interesting to override this method when implementing aCustomSchedulewhose schedule expression are harder to read. Note thatcronexpressions are already converted to human-readable strings, therefore, if your implementation is composed of multipleCronExpression, it may be sufficient to returntoString()of the active one.- Returns:
- the human-readable string, must be non-null.
-
getExpression
-
getCarbonAwareScheduleMargin
-
isCarbonAware
public boolean isCarbonAware() -
isNotCarbonAware
public boolean isNotCarbonAware() -
isRunningMoreThanOncePerMinute
public boolean isRunningMoreThanOncePerMinute()Determines whether this schedule triggers more frequently than once per minute.- Returns:
- true if this schedule will return intervals smaller than a minute (e.g., every 15 seconds or every 30 seconds), false otherwise.
-
durationBetweenSchedules
Calculates the duration between two consecutive scheduled executions.This method evaluates the schedule by computing the next execution time twice: once from a fixed base timestamp, and again from the first computed run time. The difference between these two instants represents the schedule's recurring interval.
If the schedule does not produce a second execution time (i.e., the schedule ends after the first run), the method returns
ChronoUnit.FOREVER, indicating that no further executions are scheduled.- Returns:
- the
Durationbetween the first and second scheduled run times, or a very large duration representingFOREVERif no second run exists. - Throws:
IllegalArgumentException- if the schedule implementation does not comply with the required contract of thenext()method.
-
validate
public void validate() -
compareTo
Compare twoScheduleobjects based on next occurrence.The next occurrences are calculated based on the current time.
- Specified by:
compareToin interfaceComparable<Schedule>- Parameters:
schedule- theScheduleto be compared.- Returns:
- the value
0if thisSchedulenext occurrence is equal to the argumentSchedulenext occurrence; a value less than0if thisSchedulenext occurrence is before the argumentSchedulenext occurrence; and a value greater than0if thisSchedulenext occurrence is after the argumentSchedulenext occurrence.
-
equals
-
hashCode
-
toString
-