简体   繁体   English

Rails后台进程(Heroku Rails 3+)

[英]Rails Background Process (Heroku Rails 3+)

I'm am going to set up some functionality for my app that is Rails 3.2.3 and on Heroku. 我将为我的应用程序设置一些功能,即Rails 3.2.3和Heroku。 The idea is to have a task, or job (or whatever you want to call it) run every day, to make sure user information from the external API is up to date with the user information in my db. 我们的想法是每天运行一个任务或工作(或任何你想要调用的工作),以确保外部API中的用户信息与我的数据库中的用户信息保持同步。 I'm curious what is the the best way to set this up? 我很好奇最好的方法是什么? Should it be a cron job that runs a rake task? 它应该是一个运行rake任务的cron作业吗?

Seems like there are quite a few ways to do this and I'm interested in the ways others are doing this. 似乎有很多方法可以做到这一点,我对其他人这样做的方式感兴趣。 The only way I can think to do it is to run a rake task in a cron job, but would love to figure out what best practices are, or the most simple way to do it. 我能想到的唯一方法就是在cron工作中运行rake任务,但是想知道最佳实践是什么,或者最简单的方法。 Seems like there are a lot of ways to skin this cat... lots of different tools out there too. 似乎有很多方法可以给这只猫皮肤涂抹......还有很多不同的工具。

If there was a pure rails way to do this, I think that would be better so I don't have to screw around with every system I place my app onto. 如果有一种纯粹的rails方式来做到这一点,我认为这样会更好,所以我不必使用我放置应用程序的每个系统。

There are two options. 有两种选择。 They're better than options you mentioned in your question 它们比您在问题中提到的选项更好

  1. Resque . Resque
  2. Sidekiq . Sidekiq

Try the later one. 试试后一个。 It is faster, lightweight and based on multithreading so there isn't interference with system. 它更快,更轻,基于多线程,因此不会干扰系统。 You'll need to look into scheduler of both the gem for processing everyday. 您需要查看两个gem的调度程序,以便每天处理。

Hope this helps! 希望这可以帮助!

Use the Heroku scheduler add on to the handle scheduling itself. 使用Heroku调度程序添加到句柄调度本身。 You can have it run a rake task, resque, or whatever. 你可以让它运行rake任务,resque或其他任何东西。

For a simple sync job that runs once a day, I believe having a cronjob would be sufficient and likely more stable in the long run. 对于每天运行一次的简单同步作业,我认为从长远来看,拥有一个cronjob就足够了并且可能更稳定。

Honestly, solutions such as Resque and Sidekiq is a bit overkill in my opinion (for your needs). 老实说,Resque和Sidekiq等解决方案在我看来(根据您的需求)有点矫枉过正。 You're still required to use a scheduler to send messages to these systems. 您仍然需要使用调度程序向这些系统发送消息。

Check out the gem ' whenever ' if you're looking at making the deployment and writing of crontabs easier: https://github.com/javan/whenever/ 退房的宝石“ 只要 ”如果你正在寻找做的crontab的部署和书写简单: https://github.com/javan/whenever/

Railscasts regarding 'whenever': http://railscasts.com/episodes/164-cron-in-ruby 关于'随时'的Railscasts: http//railscasts.com/episodes/164-cron-in-ruby

Here is a few to choose from : 以下是一些可供选择:

  1. resque (with resque-scheduler . But you have to use redis with it) resque (使用resque-scheduler 。但你必须使用redis)
  2. rufus-scheduler ( if you want something simple, resque uses rufus-scheduler itself) rufus-scheduler (如果你想要简单的东西,resque使用rufus-scheduler本身)
  3. You may try delayed_job with a few tricks like this one . 您可以尝试使用像这样一些技巧的delayed_job Not that great for scheduling but can use your application database. 这不是很好的安排,但可以使用您的应用程序数据库。

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

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