Skip to content

Commit 07dd369

Browse files
committed
Cache human-readable expected frequency in MonitoredJobHealthCheck
* Refactor MonitoredJobHealthCheck so that the human-readable expected job frequency (e.g., 5 minutes) is computed in the constructor and stored in a final field. This field is then used when creating the health check details. This avoids re-computing the same string every time the health check executes.
1 parent 11f042c commit 07dd369

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/kiwiproject/dropwizard/util/health/MonitoredJobHealthCheck.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class MonitoredJobHealthCheck extends HealthCheck {
9191

9292
private final MonitoredJob job;
9393
private final long expectedFrequencyMilliseconds;
94+
private final String expectedFrequencyString;
9495
private final Duration errorWarningDuration;
9596
private final String errorWarningDurationString;
9697
private final long errorWarningDurationMilliseconds;
@@ -110,6 +111,7 @@ private MonitoredJobHealthCheck(MonitoredJob job,
110111

111112
this.job = requireNotNull(job, "job is required");
112113
this.expectedFrequencyMilliseconds = requireNotNull(expectedFrequency, "expectedFrequency is required").toMilliseconds();
114+
this.expectedFrequencyString = formatMillisecondDurationWords(this.expectedFrequencyMilliseconds);
113115
this.errorWarningDuration = isNull(errorWarningDuration) ? DEFAULT_WARNING_DURATION : errorWarningDuration;
114116
this.errorWarningDurationString = formatDropwizardDurationWords(this.errorWarningDuration);
115117
this.errorWarningDurationMilliseconds = this.errorWarningDuration.toMilliseconds();
@@ -178,7 +180,7 @@ private ResultBuilder resultBuilderWith(String message, boolean healthy, Excepti
178180
.withDetail("lastSuccessfulExecutionDurationMs", lastExecutionTimeMillis)
179181
.withDetail("lastSuccessfulExecutionDuration", formatMillisecondDurationWords(lastExecutionTimeMillis))
180182
.withDetail("expectedJobFrequencyMs", expectedFrequencyMilliseconds)
181-
.withDetail("expectedJobFrequency", formatMillisecondDurationWords(expectedFrequencyMilliseconds))
183+
.withDetail("expectedJobFrequency", expectedFrequencyString)
182184
.withDetail("warningThresholdDurationMs", warningThresholdDurationMilliseconds)
183185
.withDetail("warningThresholdDuration", warningThresholdDurationString)
184186
.withDetail("recentErrorWarningDurationMs", errorWarningDurationMilliseconds)

0 commit comments

Comments
 (0)