I just started to use AWS Elastic Beanstalk with my rails app and I need to use the Resque gem for background jobs. However, despite all effort to search how to run Resque worker on Elastic Beanstalk, I haven't been able to figure out how?
How can I run Rails background jobs with Resque on AWS Elastic Beanstalk? talks about running those as services in Elastic Beanstalk containers, however, it is still very confusing.
Here my ebextentions resque.config file:
services:
sysvinit:
resque_worker:
enabled: true
ensureRunning: true
commands:
resque_starter:
rake resque:work QUEUE='*'
EDIT Now my resque.config file looks like this:
container_commands:
resque_starter: "rake resque:work QUEUE='*'"
services:
sysvinit:
resque_worker:
enabled: true
ensureRunning: true
commands:
resque_starter
And it is still not working. EDIT 2
container_commands:
resque_starter:
command: "rake resque:work QUEUE=sqs_message_sender_queue"
cwd: /var/app/current/
ignoreErrors: true
Still it shows 0 workers.
First at all, I would recommend to run resque with help of supervisord this will help you make sure that worker will be restarted if process die.
On how to run command when you do deploy every time: Log in by ssh to your beanstalk instance go to folder: /opt/elasticbeanstalk/hooks/appdeploy/ Here you will find list of hooks that execute every time when you do deploy. Also here you can put own script that will be executed every time when you do deploy. Also with same approach you can put script to hooks that responsible to application server restart and have ability to restart you background job without connection by ssh.
Another option, put your command that start background worker is use container_commands instead of commands.
Also, please have a look to best articles that I have found about customization of beanstalk: http://www.hudku.com/blog/tag/elastic-beanstalk/ it would be good start point for customization of beanstalk environment for your need. \