gpt4 book ai didi

ruby-on-rails - 让 rufus-scheduler 在 Heroku 上工作

转载 作者:行者123 更新时间:2023-12-04 05:52:36 24 4
gpt4 key购买 nike

我想使用 Rufus-Scheduler 每天发送一封邮件。我严格按照 GitHub 上的说明进行操作 here (片段,使用瘦服务器等);但是什么都没发生(没有发送邮件),我无法根据 Heroku 日志找出原因

我的代码

# config/initializers/scheduler.rb

require 'rufus-scheduler'


s = Rufus::Scheduler.singleton


# Here goes my mailing code (already tested and works well)

s.every '1d' do

Rails.logger.info "hello, it's #{Time.now}"
Rails.logger.flush
end

为了使 rufus-schedul 工作,GitHub 上是否还有其他一些未提及的要点?非常感谢

最佳答案

你可以做到这一点,但你必须了解爱好测功机的工作原理。每个免费帐户is allocated hours like this .

Accounts are given a base of 550 hours each month in which your Free dynos can run. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours of Free dyno quota.

因为 rufus-scheduler 在你的 ruby​​ app 进程中作为一个线程运行(这就是它在你运行 rails console 时开始运行的原因),只要你的服务器(我使用 puma)在运行,rufus scheduler 就会运行得很好.

缺点是,如果你在你的服务器上运行两个进程,假设你运行 puma 有 3-4 个 worker ,你将有 3-4 个调度程序同时运行,使其在一式三份/四份,所以也要记住这一点。

所以步骤很简单 - 确保你有足够的时间整个月连续运行你的测功机 - 使用像 pingdom 这样的服务,每隔几分钟 ping 你的应用程序以保持测功机处于事件状态,这样 Heroku 就不会在 30 分钟不活动后将其降速(这样做是为了释放测功机) - 这就是您需要做的一切

请记住,要运行 dyno 一个月,您将需要大约 745 小时,这是您的主要分配涵盖的(当您添加信用卡时)。如果由于某种原因你用完了时间(假设你在帐户上运行两个不同的应用程序并使用我在下面描述的方法)那么这可能会发生在你身上

A second notification will be sent when you reach 100% of your account quota, at which point your application’s dynos will be put to sleep for the remainder of that month. As a result, any apps using free dynos will not be accessible for the remainder of the month.

当您可以像其他人一样使用 heroku 调度程序来安排 rake 任务时,似乎很麻烦。

关于ruby-on-rails - 让 rufus-scheduler 在 Heroku 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35731097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com