Browse Source

fix version check debug code

Jason Rivard 2 years ago
parent
commit
c3faceb784

+ 14 - 9
server/src/main/java/password/pwm/svc/version/VersionCheckService.java

@@ -152,28 +152,33 @@ public class VersionCheckService extends AbstractPwmService
 
         final VersionCheckInfoCache localCache = cacheHolder.getVersionCheckInfoCache();
 
+        this.nextScheduledCheck = calculateNextScheduledCheck( localCache, settings );
+
+        final TimeDuration delayUntilNextExecution = TimeDuration.fromCurrent( this.nextScheduledCheck );
+
+        getExecutorService().schedule( new PeriodicCheck(), delayUntilNextExecution.asMillis(), TimeUnit.MILLISECONDS );
+
+        LOGGER.trace( getSessionLabel(), () -> "scheduled next check execution at " + StringUtil.toIsoDate( nextScheduledCheck )
+                + " in " + delayUntilNextExecution.asCompactString() );
+    }
+    
+    private static Instant calculateNextScheduledCheck( final VersionCheckInfoCache localCache, final VersionCheckSettings settings )
+    {
         final TimeDuration idealDurationUntilNextCheck = localCache.getLastError() != null && localCache.getCurrentVersion() == null
                 ? settings.getCheckIntervalError()
                 : settings.getCheckInterval();
 
         if ( localCache.getLastCheckTimestamp() == null )
         {
-            this.nextScheduledCheck = Instant.now().plus( 10, ChronoUnit.SECONDS );
+            return Instant.now().plus( 10, ChronoUnit.SECONDS );
         }
         else
         {
             final Instant nextIdealTimestamp = localCache.getLastCheckTimestamp().plus( idealDurationUntilNextCheck.asDuration() );
-            this.nextScheduledCheck = nextIdealTimestamp.isBefore( Instant.now() )
+            return nextIdealTimestamp.isBefore( Instant.now() )
                     ? Instant.now().plus( 10, ChronoUnit.SECONDS )
                     : nextIdealTimestamp;
         }
-
-        final TimeDuration delayUntilNextExecution = TimeDuration.fromCurrent( this.nextScheduledCheck );
-
-        getExecutorService().schedule( new PeriodicCheck(), delayUntilNextExecution.asMillis(), TimeUnit.MILLISECONDS );
-
-        LOGGER.trace( getSessionLabel(), () -> "scheduled next check execution at " + StringUtil.toIsoDate( nextScheduledCheck )
-                + " in " + delayUntilNextExecution.asCompactString() );
     }
 
     private class PeriodicCheck implements Runnable