Class CarbonAwarePeriod
java.lang.Object
org.jobrunr.scheduling.carbonaware.CarbonAwarePeriod
- All Implemented Interfaces:
Temporal, TemporalAccessor
Represents a period of time in which a job may be scheduled to minimize carbon emissions.
A CarbonAwarePeriod is constructed using the CarbonAware utility class. It defines a flexible scheduling window
that can be centered around a point in time, start from now until a deadline, or be bounded by a custom range.
The actual execution time within this window is determined by a carbon-aware scheduler.
Note: The scheduling window must currently span at least 3 hours. This is due to the underlying carbon intensity data being available only at an hourly resolution.
Example usages:
// Schedule before a specific deadline
CarbonAwarePeriod beforeDeadline = CarbonAware.before(Instant.parse("2025-07-01T08:00:00Z"));
// Schedule between two custom times
CarbonAwarePeriod betweenTimes = CarbonAware.between(
Instant.parse("2025-07-01T00:00:00Z"),
Instant.parse("2025-07-01T08:00:00Z")
);
// Schedule around a target time with flexibility
CarbonAwarePeriod flexible = CarbonAware.at(
Instant.parse("2025-07-01T04:00:00Z"),
Duration.ofHours(4)
);
NOTE: CarbonAwarePeriod implements Temporal as a marker interface. All temporal methods
currently throw UnsupportedOperationException and are not intended for direct time manipulation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CarbonAwarePeriodAllows to relax the scheduling of a job to minimize carbon impact.static CarbonAwarePeriodAllows to relax the scheduling of a job to minimize carbon impact.getFrom()longgetLong(TemporalField field) getTo()booleanisSupported(TemporalField field) booleanisSupported(TemporalUnit unit) plus(long amountToAdd, TemporalUnit unit) longuntil(Temporal endExclusive, TemporalUnit unit) with(TemporalField field, long newValue) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TemporalAccessor
get, query, range
-
Method Details
-
getFrom
-
getTo
-
before
Allows to relax the scheduling of a job to minimize carbon impact. The job will run before the providedtoTemporal instance.- Parameters:
to- the time expressed in java.time.Temporal before which the job must be scheduled.- Returns:
- A carbon aware period between
Instant.now()and the providedto.
-
between
Allows to relax the scheduling of a job to minimize carbon impact. The job will run between the two providedfromandtoTemporal instances as the interval. -
isSupported
- Specified by:
isSupportedin interfaceTemporal
-
with
-
plus
-
until
-
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-