Skip to content

Commit

Permalink
protect against empty string env variable for monitoring interval
Browse files Browse the repository at this point in the history
  • Loading branch information
mcook42 committed Oct 14, 2024
1 parent 516cf8c commit 4554878
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ public TimDepositController(OdeProperties odeProperties) {
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
// 3600 seconds, or one hour, was determined to be a sane default for the monitoring interval if monitoring is enabled
// but there was no interval set in the .env file
Long monitoringInterval = Long.valueOf(odeProperties.getProperty(ConfigEnvironmentVariables.ODE_TIM_INGEST_MONITORING_INTERVAL, "3600"));
String interval = odeProperties.getProperty(ConfigEnvironmentVariables.ODE_TIM_INGEST_MONITORING_INTERVAL);
// getProperty(name, default) method will not use the default value if the value is set to an empty string, so we are using getProperty(name)
// and then checking if it is null or empty to protect against the case where the value is set to an empty string in the .env file so that we can
// use Long.valueOf() without risk of a NumberFormatException.
if (interval == null || interval.isEmpty()) {
interval = "3600";
}
Long monitoringInterval = Long.valueOf(interval);

scheduledExecutorService.scheduleAtFixedRate(new TimIngestWatcher(monitoringInterval), monitoringInterval, monitoringInterval, java.util.concurrent.TimeUnit.SECONDS);
} else {
Expand Down

0 comments on commit 4554878

Please sign in to comment.