質問

I have an application written in Rails, deployed on Heroku. I used to have been working on 1 web dyno, but today I have published the app, the traffic is quite big so I decided to increase to 4 web dynos and 1 worker dynos. I don't know why always when I do heroku ps it shows:

Process   State           Command                            
--------  --------------  ---------------------------------  
web.1     up for 22s      bundle exec rails server -p $PORT  
web.2     up for 36s      bundle exec rails server -p $PORT  
web.3     up for 25s      bundle exec rails server -p $PORT  
web.4     up for 22s      bundle exec rails server -p $PORT  
worker.1  crashed for 7s  bundle exec rake jobs:work

Worker dyno crashes directly after heroku scale worker=1. Logs are like:

2012-03-11T23:12:18+00:00 heroku[worker.1]: Starting process with command `bundle exec rake jobs:work`
2012-03-11T23:12:19+00:00 heroku[worker.1]: State changed from starting to up
2012-03-11T23:12:22+00:00 app[worker.1]: rake aborted!
2012-03-11T23:12:22+00:00 app[worker.1]: Don't know how to build task 'jobs:work'
2012-03-11T23:12:22+00:00 app[worker.1]: 
2012-03-11T23:12:22+00:00 app[worker.1]: (See full trace by running task with --trace)
2012-03-11T23:12:23+00:00 heroku[worker.1]: Process exited with status 1
2012-03-11T23:12:23+00:00 heroku[worker.1]: State changed from up to crashed
2012-03-11T23:12:23+00:00 heroku[worker.1]: State changed from crashed to created
2012-03-11T23:12:23+00:00 heroku[worker.1]: State changed from created to starting
2012-03-11T23:12:32+00:00 heroku[worker.1]: Starting process with command `bundle exec rake jobs:work`
2012-03-11T23:12:32+00:00 heroku[worker.1]: State changed from starting to up
2012-03-11T23:12:36+00:00 app[worker.1]: rake aborted!
2012-03-11T23:12:36+00:00 app[worker.1]: Don't know how to build task 'jobs:work'
2012-03-11T23:12:36+00:00 app[worker.1]: 
2012-03-11T23:12:36+00:00 app[worker.1]: (See full trace by running task with --trace)
2012-03-11T23:12:37+00:00 heroku[worker.1]: Process exited with status 1
2012-03-11T23:12:37+00:00 heroku[worker.1]: State changed from up to crashed

That's it. Do you have any idea why? Web dynos are working properly. Do I have to configure something in my app to use worker dynos?

I would be also grateful if you can explain me in human words what is the logic behind dividing the heroku platform into web and worker dynos? I have read documentation number of times but I still think I missing the point to understand it as I grew up in the world where you had your storage limit and stuff.

役に立ちましたか?

解決

Workers are used for background processing, for example, sending e-mails, fetching data from some web service, in general it's for any task that takes long and you don't want your user to wait for it to see the page. This is a think that should be used for performance, because if you are using web dynos for sending like 10 e-mails, that's time that they aren't responding to user request, so you can't handle so many users.

Taks must be queued and workers should check that queue to get that job done!

So your worker crashs because you don't have any job defined, so he can waits for queues on that job. Check this gem for information on how to set a job and queue tasks.

https://github.com/defunkt/resque

Another thing that workers can be used for it's to schedule some task, like cron jobs. Here is a gem for help on that.

https://github.com/javan/whenever

I highly recommend you to watch this too videos on RailsCasts

http://railscasts.com/episodes/171-delayed-job

http://railscasts.com/episodes/271-resque

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top