lila/modules/db/src/main/Env.scala

36 lines
768 B
Scala
Raw Normal View History

2013-03-19 16:06:38 -06:00
package lila.db
2019-12-26 18:28:17 -07:00
import akka.actor.CoordinatedShutdown
2019-12-07 09:02:21 -07:00
import com.typesafe.config.Config
import play.api.Configuration
2019-12-03 17:55:45 -07:00
import reactivemongo.api._
import scala.concurrent.ExecutionContext
2013-03-19 16:06:38 -06:00
2019-12-27 09:18:45 -07:00
import lila.common.Lilakka
2019-12-07 09:02:21 -07:00
final class Env(
appConfig: Configuration,
2019-12-26 18:28:17 -07:00
shutdown: CoordinatedShutdown
)(implicit ec: ExecutionContext) {
2019-11-29 19:16:11 -07:00
2019-12-18 15:46:42 -07:00
private val driver = new AsyncDriver(appConfig.get[Config]("mongodb").some)
def asyncDb(name: String, uri: String) =
2020-05-05 22:11:15 -06:00
new AsyncDb(
name = name,
uri = uri,
driver = driver
)
def blockingDb(name: String, uri: String) =
2020-05-05 22:11:15 -06:00
new Db(
name = name,
uri = uri,
driver = driver
)
2019-12-07 09:02:21 -07:00
2019-12-27 09:18:45 -07:00
Lilakka.shutdown(shutdown, _.PhaseServiceStop, "Closing mongodb driver") { () =>
driver.close()
2019-12-26 18:28:17 -07:00
}
2013-03-19 16:06:38 -06:00
}