diff options
author | Håkon Hallingstad <hakon@oath.com> | 2018-10-23 15:44:56 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2018-10-23 15:44:56 +0200 |
commit | 629cfc4d314f761ca632ae61639905cc9d1e3fa6 (patch) | |
tree | 7281f65a07909f1185414e20e6bce4d887496057 /vespajlib | |
parent | 123c5a40b52018090a9a7d36ab2699b85bd12328 (diff) |
Enforce CC timeouts in Orchestrator 2
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/time/TimeBudget.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java index a7963df0208..449b0d6bd05 100644 --- a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java +++ b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java @@ -66,6 +66,18 @@ public class TimeBudget { }); } + /** Returns the time left, possibly negative if the deadline has passed. */ + public Optional<Duration> timeLeft() { + return timeout.map(timeout -> timeout.minus(timePassed())); + } + + /** Returns the time left as a new TimeBudget. */ + public TimeBudget timeLeftAsTimeBudget() { + Instant now = clock.instant(); + Optional<Instant> deadline = deadline(); + return new TimeBudget(clock, now, deadline.map(d -> Duration.between(now, d))); + } + private static Duration nonNegativeBetween(Instant start, Instant end) { return makeNonNegative(Duration.between(start, end)); } |