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?
我刚刚开始在我的rails应用程序中使用AWS Elastic Beanstalk,我需要将Resque gem用于后台作业。然而,尽管我们都在努力搜索如何在Elastic Beanstalk上运行Resque worker,但我还是弄清楚了怎么办?
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.
如何在AWS Elastic Beanstalk上使用Resque运行Rails后台作业?谈到在Elastic Beanstalk容器中将它们作为服务运行,然而,它仍然非常令人困惑。
Here my ebextentions resque.config file:
这里是我的ebextentions resque.config文件:
services:
sysvinit:
resque_worker:
enabled: true
ensureRunning: true
commands:
resque_starter:
rake resque:work QUEUE='*'
EDIT Now my resque.config file looks like this:
编辑现在我的resque.config文件如下所示:
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
它仍然无法正常工作。编辑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.
它仍显示0名工人。
2 个解决方案
#1
4
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.
首先,我建议在supervisord的帮助下运行resque,这将帮助您确保在进程死亡时将重新启动worker。
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.
关于每次部署时如何运行命令:通过ssh登录到beanstalk实例转到文件夹:/ opt / elasticbeanstalk / hooks / appdeploy /这里您将找到每次部署时执行的挂钩列表。此外,您还可以放置每次部署时都会执行的脚本。也可以使用相同的方法将脚本放到负责应用程序服务器重启的钩子上,并且能够在没有ssh连接的情况下重新启动后台作业。
Another option, put your command that start background worker is use container_commands instead of commands.
另一个选项是,启动后台工作程序的命令是使用container_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. \
另外,请查看我发现的有关beanstalk自定义的最佳文章:http://www.hudku.com/blog/tag/elastic-beanstalk/这将是根据您的需求定制beanstalk环境的良好起点。 \
#2
7
I think it is suboptimal to run queues, like Resque, inside Elastic Beanstalk web environments. A web environment is intended to host web applications and spawn new instances when traffic and load increases. However, it would not make sense to have multiple Resque queues, each running on one of the instances.
我认为在Elastic Beanstalk Web环境中运行队列(如Resque)并不是最理想的。 Web环境旨在托管Web应用程序,并在流量和负载增加时生成新实例。但是,拥有多个Resque队列是没有意义的,每个队列都运行在其中一个实例上。
Elastic Beanstalk offers worker environments which are intended to host code that executes background tasks. These worker environments pull jobs from an Amazon SQS queue (which makes an additional queue solution, like Resque, obsolete). An Amazon SQS queue scales easily and is easier to maintain (AWS just does it for you).
Elastic Beanstalk提供工作者环境,用于托管执行后台任务的代码。这些工作环境从Amazon SQS队列中拉出作业(这会产生额外的队列解决方案,如Resque,已过时)。 Amazon SQS队列易于扩展,易于维护(AWS只为您完成)。
To use worker environments, which come with Amazon SQS queues, makes more sense, as it is out of the box supported and fits nicely into the Elastic Beanstalk landscape. There also exists a gem, Active Elastic Job, which makes it simple for Rails >= 4.2 applications to run background tasks in worker environments.
使用Amazon SQS队列附带的工作环境更有意义,因为它支持开箱即用,非常适合Elastic Beanstalk环境。还有一个gem,Active Elastic Job,它使Rails> = 4.2应用程序在工作环境中运行后台任务变得简单。
Disclaimer: I'm the author of Active Elastic Job.
免责声明:我是Active Elastic Job的作者。
#1
4
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.
首先,我建议在supervisord的帮助下运行resque,这将帮助您确保在进程死亡时将重新启动worker。
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.
关于每次部署时如何运行命令:通过ssh登录到beanstalk实例转到文件夹:/ opt / elasticbeanstalk / hooks / appdeploy /这里您将找到每次部署时执行的挂钩列表。此外,您还可以放置每次部署时都会执行的脚本。也可以使用相同的方法将脚本放到负责应用程序服务器重启的钩子上,并且能够在没有ssh连接的情况下重新启动后台作业。
Another option, put your command that start background worker is use container_commands instead of commands.
另一个选项是,启动后台工作程序的命令是使用container_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. \
另外,请查看我发现的有关beanstalk自定义的最佳文章:http://www.hudku.com/blog/tag/elastic-beanstalk/这将是根据您的需求定制beanstalk环境的良好起点。 \
#2
7
I think it is suboptimal to run queues, like Resque, inside Elastic Beanstalk web environments. A web environment is intended to host web applications and spawn new instances when traffic and load increases. However, it would not make sense to have multiple Resque queues, each running on one of the instances.
我认为在Elastic Beanstalk Web环境中运行队列(如Resque)并不是最理想的。 Web环境旨在托管Web应用程序,并在流量和负载增加时生成新实例。但是,拥有多个Resque队列是没有意义的,每个队列都运行在其中一个实例上。
Elastic Beanstalk offers worker environments which are intended to host code that executes background tasks. These worker environments pull jobs from an Amazon SQS queue (which makes an additional queue solution, like Resque, obsolete). An Amazon SQS queue scales easily and is easier to maintain (AWS just does it for you).
Elastic Beanstalk提供工作者环境,用于托管执行后台任务的代码。这些工作环境从Amazon SQS队列中拉出作业(这会产生额外的队列解决方案,如Resque,已过时)。 Amazon SQS队列易于扩展,易于维护(AWS只为您完成)。
To use worker environments, which come with Amazon SQS queues, makes more sense, as it is out of the box supported and fits nicely into the Elastic Beanstalk landscape. There also exists a gem, Active Elastic Job, which makes it simple for Rails >= 4.2 applications to run background tasks in worker environments.
使用Amazon SQS队列附带的工作环境更有意义,因为它支持开箱即用,非常适合Elastic Beanstalk环境。还有一个gem,Active Elastic Job,它使Rails> = 4.2应用程序在工作环境中运行后台任务变得简单。
Disclaimer: I'm the author of Active Elastic Job.
免责声明:我是Active Elastic Job的作者。