4

I need to run some code only once when I starts the play server. When using the GlobalSettings.OnStart() I notice that the code is executed only after the first (http) request to the server. Any idea how can I run my code just after the server starts and before any request is sent?

Thanks

2 Answers2

11

That is the behavior when the application is in development mode, play run. When it's running in production mode, play start, then your onStart method will run immediately when the application starts prior to any requests.

estmatic
  • 3,449
  • 1
  • 19
  • 28
  • Thanks you very much. it answered my question and solved my problem. I wonder if I missed this in the Play documentation as I don't recall seeing this and I read most of the docs. – user2696705 Aug 20 '13 at 08:17
  • What is the motivation for this difference between production and dev? – matanster Jan 17 '15 at 17:32
1

You can emulate that (or I should say, workaround this unfortunate dichotomous design), by using this plugin, which, I find useful also in general:

addSbtPlugin("com.jamesward" % "play-auto-refresh" % "0.0.11") (plugins.sbt)

And no, it is not really currently documented in any right place, that this is how OnStart works.

matanster
  • 15,072
  • 19
  • 88
  • 167