diff options
author | HÃ¥kon Hallingstad <hakon@oath.com> | 2018-10-30 09:22:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-30 09:22:27 +0100 |
commit | 47972b55d383e899e5eb3d2af24e631ae04d4c4c (patch) | |
tree | 5373df76e37ff5083964d7c50f14e6b9a6e1cdc7 /vespajlib/src/main/java/com/yahoo | |
parent | edee5b90c4a0b0bba89a801952ab4c883aa39b4b (diff) |
Revert "Revert "Revert "Revert "Enforce CC timeouts in Orchestrator 2""""
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo')
-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)); } |