Skip to content

Commit f783773

Browse files
committedNov 5, 2016
implement configurable fetch interval
1 parent bde5f4d commit f783773

6 files changed

+20
-8
lines changed
 

‎app/clients/ClientsModule.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ trait ClientsModule {
1212
def wsClient: WSClient
1313

1414
implicit def configuration: Configuration
15+
def mandatoryPropertyMissing(path: String): Nothing
1516

1617
implicit val executionContext: ExecutionContext
1718
implicit val materializer: Materializer
1819

19-
private def mandatoryPropertyMissing(path: String): Nothing = throw new UnconfiguredApplicationException(s"Missing mandatory property in application.conf: '$path'")
20-
2120
lazy val carjumpBaseUrl: CarjumpBaseUrl = CarjumpBaseUrl(new URL(configuration.getString(carjumpUrlPath)
2221
.getOrElse(mandatoryPropertyMissing(carjumpUrlPath))))
2322

‎app/jobs/CarjumpFetchInterval.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package jobs
2+
3+
import scala.concurrent.duration.FiniteDuration
4+
5+
case class CarjumpFetchInterval(value: FiniteDuration) extends AnyVal

‎app/jobs/FetchingActor.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import scala.concurrent.duration.FiniteDuration
88
import scala.concurrent.duration._
99
import scala.util.control.NonFatal
1010

11-
class FetchingActor(interval: FiniteDuration, apiService: CarjumpApiService) extends Actor with ActorLogging with FSM[FetchingActor.State, FetchingActor.Data] {
11+
class FetchingActor(interval: CarjumpFetchInterval, apiService: CarjumpApiService) extends Actor with ActorLogging with FSM[FetchingActor.State, FetchingActor.Data] {
1212
import FetchingActor._
1313
implicit val ec = context.dispatcher
1414

1515
startWith(Stopped, Uninitialized)
1616

1717
when(Stopped) {
1818
case Event(Start, _)
19-
log.info("Fetching actor starting up..")
20-
val scheduleHook = context.system.scheduler.schedule(1.seconds, interval)(self ! Fetch)
19+
log.info(s"Fetching actor starting up, re-fetch every $interval")
20+
val scheduleHook = context.system.scheduler.schedule(1.seconds, interval.value)(self ! Fetch)
2121
goto(Idle) using FetchData(scheduleHook, Seq.empty)
2222

2323
case Event(CacheValue, _)

‎app/jobs/JobsModule.scala

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ trait JobsModule {
1818
implicit def configuration: Configuration
1919

2020
implicit val materializer: Materializer
21-
21+
def mandatoryPropertyMissing(path: String): Nothing
2222
def carjumpClient: CarjumpClient
2323
def apiService: CarjumpApiService
24-
import scala.concurrent.duration._
25-
val duration = 30.seconds
24+
25+
lazy val fetchInterval: CarjumpFetchInterval = {
26+
import scala.concurrent.duration._
27+
val path = "carjump.fetchIntervalSeconds"
28+
val fetchIntervalSeconds = configuration.getInt(path).getOrElse(mandatoryPropertyMissing(path))
29+
CarjumpFetchInterval(fetchIntervalSeconds.seconds)
30+
}
2631

2732
lazy val jobsSupervisorActor = {
2833
def fetchingActor = wire[FetchingActor]

‎app/launch/CarjumpModule.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package launch
22

3+
import clients.UnconfiguredApplicationException
34
import scala.concurrent.{ ExecutionContext, Future, blocking }
45

56
import clients.ClientsModule
@@ -17,6 +18,7 @@ trait CarjumpModule
1718
with ClientsModule
1819
with SLF4JLogging {
1920

21+
def mandatoryPropertyMissing(path: String): Nothing = throw new UnconfiguredApplicationException(s"Missing mandatory property in application.conf: '$path'")
2022
def configuration: Configuration
2123
def applicationLifecycle: ApplicationLifecycle
2224
override implicit val executionContext: ExecutionContext

‎conf/additional-application.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
carjump {
22
url = "http://challenge.carjump.net"
3+
fetchIntervalSeconds = 35
34
}

0 commit comments

Comments
 (0)
Please sign in to comment.