From ba36521578a55088c6e38d50b616af85eb33cf19 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Fri, 4 Jun 2021 11:42:11 +0200 Subject: Return success factor --- .../main/java/com/yahoo/concurrent/maintenance/Maintainer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'vespajlib/src/main/java/com/yahoo') diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java index fb2339a4334..2a9e6dda6b6 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java @@ -90,7 +90,12 @@ public abstract class Maintainer implements Runnable { * Note that this indicates whether something is wrong, so e.g if the call did nothing because it should do * nothing, 1.0 should be returned. */ - protected abstract boolean maintain(); + protected abstract double maintain(); + + /** Convenience methods to convert attempts and failures into a success factor */ + protected final double asSuccessFactor(int attempts, int failures) { + return attempts == 0 ? 1.0 : 1 - (double)failures / attempts; + } /** Returns the interval at which this job is set to run */ protected Duration interval() { return interval; } @@ -102,7 +107,7 @@ public abstract class Maintainer implements Runnable { jobMetrics.starting(name()); double successFactor = 0; try (var lock = jobControl.lockJob(name())) { - successFactor = maintain() ? 1.0 : 0.0; + successFactor = maintain(); if (successFactor > 0.0) jobMetrics.recordCompletionOf(name()); } catch (UncheckedTimeoutException e) { -- cgit v1.2.3