diff --git a/akka-loader/src/main/scala/LoaderApp.scala b/akka-loader/src/main/scala/LoaderApp.scala index 7c5c4935..afcffbb8 100644 --- a/akka-loader/src/main/scala/LoaderApp.scala +++ b/akka-loader/src/main/scala/LoaderApp.scala @@ -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._ @@ -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) } diff --git a/akka-loader/src/main/scala/cli/CommandLine.scala b/akka-loader/src/main/scala/cli/CommandLine.scala index bf0f4d70..c8c0736f 100644 --- a/akka-loader/src/main/scala/cli/CommandLine.scala +++ b/akka-loader/src/main/scala/cli/CommandLine.scala @@ -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)