每分钟运行一次的邮件程序的最佳 Rails 解决方案 [英] Best rails solution for a mailer that runs every minute

查看:27
本文介绍了每分钟运行一次的邮件程序的最佳 Rails 解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它每分钟检查一次数据库,以查找当时应该发送的任何电子邮件.我正在考虑将其设为每分钟由 cron 作业运行的 rake 任务.有没有更好的解决方案?

I have an application that checks a database every minute for any emails that are supposed to be sent out at that time. I was thinking about making this a rake task that would be run by a cron job every minute. Would there be a better solution to this?

据我所知,这并不理想,因为 rake 必须每分钟加载整个 Rails 环境,这变得很昂贵.

From what I have read, this isn't ideal because rake has to load the entire rails environment every minute and this becomes expensive.

想法?

谢谢.

推荐答案

  1. 您可以使用backgroundrb.但是,这会占用主 Rails 应用的内存,因为它会生成一个专用于 backgroundrb 的 Ruby 实例.
  2. 您还可以在主应用程序中定义一个 SystemController(或等效的),其中的各种操作对应于您的应用程序应执行的各种家务.您可以使用 wgetcurlcrontab 中生产"它,优点是它与您的主应用程序共享资源.根据您的偏执程度或您是否容易受到 DOS(或其他类型的攻击)将此类控制器暴露给外部世界的脆弱性,您可以选择阻止从环回以外的地址访问该控制器的 URL(理想情况下,在您的反向代理中,或者来自控制器本身.)
  1. You can use backgroundrb. This, however, will eat up memory away from your main Rails app as it will spawn one Ruby instance exclusive to backgroundrb.
  2. You can also define a SystemController (or equivalent) in your main application, with various actions corresponding to the various household tasks your application should perform. You can "prod" it from crontab using wget or curl, the advantage being that it shares resources with your main application. Depending on how paranoid or you are, or on how vulnerable to DOS (or other types of attacks) exposing such a controller to, possibly, the outside world, you may choose to block access to this controller's URL from addresses other than the loopback (ideally in your reverse proxy, alternatively from the controller itself.)

这篇关于每分钟运行一次的邮件程序的最佳 Rails 解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆