Skip to content

Commit

Permalink
akka-loader: "auto" entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackmorse committed Feb 24, 2024
1 parent 49063e8 commit 2559ea8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion akka-loader/src/main/scala/LoaderApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory
import scheduler.{AbstractScheduler, CupScheduler, LeagueScheduler}
import utils.WorldDetailsSingleRequest

import java.util.Calendar
import scala.concurrent.Await
import scala.concurrent.duration._

Expand Down Expand Up @@ -57,7 +58,19 @@ object LoaderApp extends App {
Await.result(TeamRankJoiner.joinTeamRankings(config, league), 3.minute)
})
case LoadScheduledConfig(entity, lastMatchWindow) =>
val (taskExecutorActor, scheduler) = executorAndScheduler(entity, lastMatchWindow, executorActorFactory, worldDetails)
val realEntity = if (entity == "auto") {
val c = Calendar.getInstance()
val dayOfWeek = c.get(Calendar.DAY_OF_WEEK)
if (Set(Calendar.FRIDAY, Calendar.SATURDAY, Calendar.SUNDAY, Calendar.MONDAY).contains(dayOfWeek)) {
"league"
} else {
"cup"
}
} else {
entity
}
logger.info(s"Entity type: $entity")
val (taskExecutorActor, scheduler) = executorAndScheduler(realEntity, lastMatchWindow, executorActorFactory, worldDetails)
scheduler.loadScheduled()
actorSystem.scheduler.scheduleWithFixedDelay(0.second , 5.second)(() => taskExecutorActor ! TryToExecute)
}
Expand Down
5 changes: 4 additions & 1 deletion akka-loader/src/main/scala/cli/CommandLine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class CommandLine(arguments: Array[String]) extends ScallopConf(arguments) {
val teamRankings = new Subcommand("teamRankings") {
val league = opt[String](required = false)
}
val loadScheduled = new EntitySubcommand("loadScheduled") {}
val loadScheduled = new Subcommand("loadScheduled") {
val lastMatchWindow = opt[Int](required = false, default = Some(4))
val entity = opt[String](required = true, validate = ent => ent == "league" || ent == "cup" || ent == "auto")
}
addSubcommand(schedule)
addSubcommand(load)
addSubcommand(loadScheduled)
Expand Down

0 comments on commit 2559ea8

Please sign in to comment.