Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: What to do when your dyno/worker crashes?

I have a worker doing some processing 24/7. However, sometimes the code crashes and it needs to be restarted (even if I catch the exception, I have to restart the worker in order for it to work).

What do you do when this happens or am I doing something wrong and this shouldn't happen at all? Does your dynos/workers crash or it is just me?

thanks

like image 544
donald Avatar asked Jun 14 '11 10:06

donald


People also ask

Do Heroku dynos restart?

Dynos are ephemeral by design. They are cycled (restarted) at least once a day to help maintain the health of your app and overall system, and they permit graceful exit to process remaining requests. For apps running multiple dynos, each will be cycled at different intervals.

Why is my Heroku app crashing?

If your Procfile is pointing to the wrong server file. e.g If your server is in server. js and your Procfile points to app. js this would definitely crash your app and Heroku would greet you with the H10-App crashed error code message.

Do worker dynos sleep Heroku?

In addition to the web dyno sleeping, the worker dyno (if present) will also sleep. Free web dynos do not consume free dyno hours while sleeping. If a sleeping web dyno receives web traffic, it will become active again after a short delay (assuming your account has free dyno hours available).


2 Answers

Latest command to restart a specific heroku web worker (2014):

heroku ps:restart web.1

(tested on Cedar stack)

like image 191
AmpT Avatar answered Sep 30 '22 18:09

AmpT


Heroku is supposed to restart a worker every time it crashes. As far as I know, you don't have to select or configure anything. Whatever is in your jobs:work task will be executed as soon as it fails.

In the event that you are heavily dependent on background jobs in your web app. You could create a rake task that finds the last record to be updated and execute a background job to update it. Or perhaps automate the rake task to find the rest of the records that need updating, since the last crash.

Alternatively, you force worker restart manually as indicated in this article (using delayed_job):

heroku workers 0; 
heroku workers 1;

Or perhaps you can restart a specific worker by doing (mentioned in this article):

heroku restart worker.1

By the way, try the 1.9 stack. Make sure your app is 1.9.2 compatible, before doing so. Hopefully crashes are less frequent there:

heroku stack:migrate bamboo-mri-1.9.2

In the event, that such issues still arise. Best to contact Heroku support. They are very responsive at what they do.

like image 39
Christian Fazzini Avatar answered Sep 30 '22 17:09

Christian Fazzini