简体   繁体   English

如何在AWS Elastic Beanstalk上使用Resque运行Rails后台作业?

[英]How can I run Rails background jobs with Resque on AWS Elastic Beanstalk?

I am running my rails app on the AWS Elastic Beanstalk platform, which is running a single EC2 instance with Auto Scaling & Elastic Load Balancing. 我在AWS Elastic Beanstalk平台上运行我的rails应用程序,该平台运行带有Auto Scaling和Elastic Load Balancing的单个EC2实例。

I'm wondering how to run resque , delayed_job or sidekicq or some other solution for background jobs on Elastic Beanstalk. 我想知道如何在Elastic Beanstalk上运行resquedelayed_jobsidekicq或其他一些后台作业解决方案。

What are the possible options for background jobs on Elastic Beanstalk? Elastic Beanstalk上的后台作业有哪些可能的选项?

I created a gem, Active Elastic Job , as a solution for background jobs of Rails applications running on Elastic Beanstalk. 我创建了一个gem, Active Elastic Job ,作为在Elastic Beanstalk上运行的Rails应用程序的后台作业的解决方案。 It makes use of Elastic Beanstalk worker environments , which are intended to be used for background tasks of Elastic Beanstalk applications. 它利用Elastic Beanstalk 工作线程环境 ,这些环境旨在用于Elastic Beanstalk应用程序的后台任务。

Advantages are: 优点是:

  • You can use the same code base for executing background jobs, no need to branch off a dedicated version of your application to run in worker environments, 您可以使用相同的代码库来执行后台作业,无需分支应用程序的专用版本以在工作环境中运行,
  • make use of Elastic Beanstalk autoscale capabilities, 利用Elastic Beanstalk自动缩放功能,
  • no need to set up external EC2 instances or services to run aa queueing backend like resque or sidekiq , 无需设置外部EC2实例或服务来运行排队后端,如resquesidekiq
  • no need to customize Elastic Beanstalk containers. 无需自定义Elastic Beanstalk容器。
  • keep simplicity of Elastic Beanstalk's predefined infrastructure. 保持Elastic Beanstalk预定义基础架构的简单性。

However, this gem is only compatible with Rails >= 4.2 applications. 但是,此gem仅与Rails> = 4.2应用程序兼容。

Best way to start/stop/restart background jobs could be via init scripts for these tasks. 启动/停止/重启后台作业的最佳方法可以是通过这些任务的init脚本。 You could have these init scripts triggered as services when instances are launched. 启动实例时,可以将这些init脚本作为服务触发。 More about Customizing ElasticBeanstalk containers for services here . 有关在此处为服务自定义ElasticBeanstalk容器的更多信息。

Once done, you could freeze your init scripts by creating an AMI of your instance and then launching instances out of this custom AMI with auto-scaling. 完成后,您可以通过创建实例的AMI来冻结init脚本,然后使用自动缩放功能从此自定义AMI启动实例。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM