summaryrefslogtreecommitdiffstats
path: root/vespajlib/src
diff options
context:
space:
mode:
authorHÃ¥kon Hallingstad <hakon@oath.com>2018-10-31 14:20:31 +0100
committerGitHub <noreply@github.com>2018-10-31 14:20:31 +0100
commit10b69f509f0e91c8dddcf8d695a5dcafa36f41ba (patch)
tree88e78c5d2cdb111565cdf2c91083fce66edc69f8 /vespajlib/src
parentb4e2ae6213c248307b274f3012c56ec1fdec14e9 (diff)
parenteaea833fd78b37557b5d18a112fb63d1f04da3be (diff)
Merge pull request #7491 from vespa-engine/revert-7490-revert-7472-revert-7470-revert-7424-hakonhall/enforce-cc-timeouts-in-orchestrator-2
Enforce CC timeouts in Orchestrator [4]
Diffstat (limited to 'vespajlib/src')
-rw-r--r--vespajlib/src/main/java/com/yahoo/time/TimeBudget.java12
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));
}