Dr.Haribo
Dr.Haribo

Reputation: 1778

Correct way to handle fatal error under Play framework

If your Play app discovers it is unable to operate, for instance because of missing mandatory configuration items, what is the correct way of handling that?

Log an error and System.exit() ? Or is there a "nicer" way?

Upvotes: 3

Views: 168

Answers (1)

wwkudu
wwkudu

Reputation: 2796

From a little research, it seems there is a method for closing down the actual play application but this does not shut down the app server (e.g. Netty) (at least in dev mode). Combining this with System.exit() appears to do a "safe" shutdown by first dealing with Play:

play.api.Play.stop
System.exit(-1)

But it will be interesting to test it in your specific circumstances.

This discussion talks more about the meaning of shutting down safely and has an example of Play.stop being called.

BTW, Netty seems to have a stop method, which does a few other things besides the Play.stop call.

Caveat: have not used this in anger.

Upvotes: 1

Related Questions