
上QQ阅读APP看书,第一时间看更新
Scheduler
Scheduler takes the frequency constant from the application.conf and uses the Actor system to send an update message (the content does not matter; SchedulerActor reacts to any message) to SchedulerActor every X seconds:
class Scheduler @Inject()
(val system: ActorSystem, @Named("scheduler-actor") val schedulerActor: ActorRef, configuration: Configuration)(implicit ec: ExecutionContext) {
//constants.frequency is set in conf/application.conf file
val frequency = configuration.getInt("constants.frequency").get
var actor = system.scheduler.schedule(
0.microseconds, //initial delay: whether execution starts immediately after app launch
frequency.seconds, //every X seconds, specified above
schedulerActor,
"update")
}