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
|
2020-07-05 11:09:49 -06:00
|
|
|
import play.api.Configuration
|
2019-12-03 17:55:45 -07:00
|
|
|
import reactivemongo.api._
|
2020-07-05 11:09:49 -06:00
|
|
|
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
|
2020-07-05 11:09:49 -06:00
|
|
|
)(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)
|
2018-12-17 02:40:51 -07:00
|
|
|
|
2020-07-05 11:09:49 -06:00
|
|
|
def asyncDb(name: String, uri: String) =
|
2020-05-05 22:11:15 -06:00
|
|
|
new AsyncDb(
|
|
|
|
name = name,
|
|
|
|
uri = uri,
|
|
|
|
driver = driver
|
|
|
|
)
|
|
|
|
|
2020-07-05 11:09:49 -06:00
|
|
|
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") { () =>
|
2020-09-29 01:51:32 -06:00
|
|
|
driver.close()
|
2019-12-26 18:28:17 -07:00
|
|
|
}
|
2013-03-19 16:06:38 -06:00
|
|
|
}
|