migrate importer module

rm0193-mapreduce
Thibault Duplessis 2019-12-03 11:08:27 -06:00
parent 958a2d6262
commit 85dbd38f97
5 changed files with 13 additions and 28 deletions

View File

@ -487,9 +487,6 @@ fishnet {
application {
global="lila.app.Global"
}
importer {
delay = 50 milliseconds
}
insight {
mongodb {
uri = "mongodb://127.0.0.1:27017/lichess-insight"

View File

@ -2,7 +2,7 @@ package lila.importer
import chess._
object Chess960 {
private object Chess960 {
def isStartPosition(board: Board) = board valid true && {

View File

@ -9,7 +9,7 @@ import scalaz.Validation.FlatMap._
import lila.game._
private[importer] final class DataForm {
private final class DataForm {
lazy val importForm = Form(mapping(
"pgn" -> nonEmptyText.verifying("invalidPgn", p => checkPgn(p).isSuccess),
@ -19,7 +19,7 @@ private[importer] final class DataForm {
def checkPgn(pgn: String): Valid[Preprocessed] = ImportData(pgn, none).preprocess(none)
}
private[importer] case class TagResult(status: Status, winner: Option[Color])
private case class TagResult(status: Status, winner: Option[Color])
case class Preprocessed(
game: NewGame,
replay: Replay,

View File

@ -1,23 +1,14 @@
package lila.importer
import com.typesafe.config.Config
import com.softwaremill.macwire._
import scala.concurrent.duration._
final class Env(
config: Config,
gameRepo: lila.game.GameRepo,
scheduler: akka.actor.Scheduler
) {
private val Delay = config duration "delay"
lazy val forms = wire[DataForm]
lazy val forms = new DataForm
lazy val importer = new Importer(Delay, scheduler)
}
object Env {
lazy val current = "importer" boot new Env(
config = lila.common.PlayApp loadConfig "importer",
scheduler = lila.common.PlayApp.system.scheduler
)
lazy val importer = wire[Importer]
}

View File

@ -1,31 +1,28 @@
package lila.importer
import scala.concurrent.duration._
import akka.actor.ActorRef
import chess.format.FEN
import chess.{ Status, Situation }
import lila.game.{ Game, GameRepo }
final class Importer(
delay: FiniteDuration,
gameRepo: GameRepo,
scheduler: akka.actor.Scheduler
) {
def apply(data: ImportData, user: Option[String], forceId: Option[String] = None): Fu[Game] = {
def gameExists(processing: => Fu[Game]): Fu[Game] =
GameRepo.findPgnImport(data.pgn) flatMap { _.fold(processing)(fuccess) }
gameRepo.findPgnImport(data.pgn) flatMap { _.fold(processing)(fuccess) }
gameExists {
(data preprocess user).future flatMap {
case Preprocessed(g, replay, initialFen, _) =>
val game = forceId.fold(g.sloppy)(g.withId)
(GameRepo.insertDenormalized(game, initialFen = initialFen)) >> {
game.pgnImport.flatMap(_.user).isDefined ?? GameRepo.setImportCreatedAt(game)
(gameRepo.insertDenormalized(game, initialFen = initialFen)) >> {
game.pgnImport.flatMap(_.user).isDefined ?? gameRepo.setImportCreatedAt(game)
} >> {
GameRepo.finish(
gameRepo.finish(
id = game.id,
winnerColor = game.winnerColor,
winnerId = None,