Load Play! environment mode in another main process

23 Views Asked by At

I have a Play application that contains a Main running another process. At Heroku, it is another dyno running this process.

I need to load the Mode (Dev, Test, Prod) which my Play application is running into the Main process Application, here:

val app: Application = GuiceApplicationBuilder().build().

This is what I have:

object ConsumersApp {


  def main(args: Array[String]): Unit = {
    val app: Application = GuiceApplicationBuilder()
      .loadConfig(env => Configuration.load(env))
      .build()

      //...
  }

}

But .loadConfig(env => Configuration.load(env)) actually returns Mode.Test even when in production environment.

1

There are 1 best solutions below

0
codefinger On

You can pass the -main option to the target/universal/stage/bin command in your Procfile. For example:

worker: target/universal/stage/bin/play-app -main com.example.MyClass

I'm not sure if there is a specification for this flag, but the code is on Github