migrate importer module
parent
958a2d6262
commit
85dbd38f97
|
@ -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"
|
||||
|
|
|
@ -2,7 +2,7 @@ package lila.importer
|
|||
|
||||
import chess._
|
||||
|
||||
object Chess960 {
|
||||
private object Chess960 {
|
||||
|
||||
def isStartPosition(board: Board) = board valid true && {
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue