0
votes

I have some Play Framework models looking similar to:

class BookieRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
  val dbConfig = dbConfigProvider.get[JdbcProfile]
  val db = dbConfig.db
  import dbConfig.profile.api._

  def all: Future[Seq[BookiesRow]] =
    db.run(Bookies.result)
}

My web application runs fine and is able to use these models. However I need to invoke some 'standalone' part of my app to gather the data from websites and put it into DB. What's the recommended way to acquire access to these model's methods in my objects extending App and being started by crontab? Is StaticApplication what I need here? Doesn't it mean that I would have 2 apps (the standard one and the static one) running concurrently then?

1

1 Answers

0
votes

So it seems like in previous versions of Play Framework this was possible through GlobalSettings.

If you are using version 2.6.x, they suggest putting the code you need to run on start-up in the constructor a dependency injected class. https://www.playframework.com/documentation/2.6.x/GlobalSettings

If you are on a version of Play Framework before 2.6.x, you should still be able to do it, by looking at https://playframework.com/documentation/2.0/ScalaGlobal

Good luck!