Skip to content

Instantly share code, notes, and snippets.

@megafarad
Created October 15, 2022 04:10
Show Gist options
  • Save megafarad/cd2320ff395b43e69176c36373ecefb8 to your computer and use it in GitHub Desktop.
Save megafarad/cd2320ff395b43e69176c36373ecefb8 to your computer and use it in GitHub Desktop.
package com.megafarad.jmdictapi
import akka.actor._
import akka.actor.typed.scaladsl.adapter._
import akka.http.scaladsl.Http
import com.megafarad.jmdictapi.api.SearchRoutes
import com.megafarad.jmdictapi.importer.Importer
import com.typesafe.akka.extension.quartz.QuartzSchedulerTypedExtension
import com.typesafe.scalalogging.StrictLogging
import java.util.TimeZone
import scala.concurrent.ExecutionContext
object Main extends App with ServerConfig with ImporterConfig with StrictLogging {
implicit val system: ActorSystem = ActorSystem()
val typedSystem: typed.ActorSystem[Nothing] = system.toTyped
implicit val executionContext: ExecutionContext = system.dispatcher
val modules = new ModulesWiring with SearchRoutes {
override def _system: ActorSystem = system
}
val routes = modules.searchRoutes
logger.info(s"Server start at : $host:$port")
Http().newServerAt(host, port).bind(routes)
val scheduler: QuartzSchedulerTypedExtension = QuartzSchedulerTypedExtension(typedSystem)
val importerRef: typed.ActorRef[Importer.Import] = system.spawn(Importer(mongoDb = modules.mongo), "importer")
scheduler.createTypedJobSchedule(name = "import-job", receiver = importerRef,
Importer.DownloadFile(source), cronExpression = schedule, timezone = TimeZone.getTimeZone("America/Los_Angeles"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment