Skip to content

Commit

Permalink
Make refresh interval a strongly-typed Duration
Browse files Browse the repository at this point in the history
I'm trying to find out why `PublicSettings` in s3-uploader (guardian/s3-upload#58)
didn't log that the panda settings had changed - maybe the refresh schedule did not start, or
possibly the interval was no good (rounded to nothing)?
  • Loading branch information
rtyley committed Sep 13, 2024
1 parent f1b24fb commit 053b9f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.gu.pandomainauth

import com.amazonaws.services.s3.AmazonS3
import com.gu.pandomainauth.model.PanDomainAuthSettings
import com.gu.pandomainauth.service.CryptoConf
import org.slf4j.LoggerFactory

import java.util.concurrent.Executors.newScheduledThreadPool
import java.util.concurrent.ScheduledExecutorService
Expand Down Expand Up @@ -40,7 +38,7 @@ class PanDomainAuthSettingsRefresher(
_.signingAndVerification,
scheduler
)
settingsRefresher.start(1)
settingsRefresher.start()

def settings: PanDomainAuthSettings = settingsRefresher.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import com.gu.pandomainauth.service.CryptoConf
import com.gu.pandomainauth.service.CryptoConf.Verification

import java.security.PublicKey
import java.time.Duration
import java.time.Duration.ofMinutes
import java.util.concurrent.Executors.newScheduledThreadPool
import java.util.concurrent.{Executors, ScheduledExecutorService}
import scala.concurrent.duration._

/**
* Class that contains the static public settings and includes mechanism for fetching the public key. Once you have an
Expand All @@ -28,7 +29,7 @@ class PublicSettings(loader: Settings.Loader, scheduler: ScheduledExecutorServic
scheduler
)

def start(interval: FiniteDuration = 60.seconds): Unit = settingsRefresher.start(interval.toMinutes.toInt)
def start(interval: Duration = ofMinutes(1)): Unit = settingsRefresher.start(interval)

def verification: Verification = settingsRefresher.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import com.gu.pandomainauth.service.CryptoConf.Verification
import org.slf4j.{Logger, LoggerFactory}

import java.io.ByteArrayInputStream
import java.time.Duration
import java.time.Duration.ofMinutes
import java.util.Properties
import java.util.concurrent.TimeUnit.MINUTES
import java.util.concurrent.TimeUnit.MILLISECONDS
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.{Executors, ScheduledExecutorService}
import scala.jdk.CollectionConverters._
Expand Down Expand Up @@ -92,7 +94,10 @@ object Settings {

private val logger = LoggerFactory.getLogger(getClass)

def start(interval: Int): Unit = scheduler.scheduleAtFixedRate(() => refresh(), 0, interval, MINUTES)
def start(interval: Duration = ofMinutes(1)): Unit = {
logger.info(s"Starting refresh schedule with an interval of $interval")
scheduler.scheduleAtFixedRate(() => refresh(), 0, interval.toMillis, MILLISECONDS)
}

def loadAndParseSettings(): SettingsResult[A] =
loader.loadAndParseSettingsMap().flatMap(settingsParser)
Expand Down

0 comments on commit 053b9f8

Please sign in to comment.