Idiomatic way to restart a Phoenix app from inside?

I have a Phoenix app running in Heroku and using Oban for background jobs. I still don’t know why but it can happen that Oban gets stuck and doesn’t pick any job - happily, restarting the app with heroku restart fixes this problem… until it happens again of course.

So, as a temporary measure until we catch the bug, I’d sleep better if I could monitor the app for stuck jobs and in that case, automatically restart the server.

I can do that using the Heroku API but I wonder if there’s an idiomatic way to restart an Elixir / Phoenix app from inside. Is there one?

1 Like

Don’t know much about Oban, but you could send a message to the main supervisor or queue process specially if they have a known name, using Process.exit/2 this will probably force a restart of the process without taking your system down for a restart.

To check if the queue need a restart you could use a simple genserver with periodically checking the queue the same way you do to know it is stuck then issuing the exit.

Hope this gives some light.

1 Like