Ruby 根据yml文件设置定期调用函数。(heroku证明)
我正在开发一个应用程序,它将读取存储在yaml文件中的rss提要列表,并在提要中有新项目时向Hipchat发送消息 下面是myfeeds.yml文件的结构Ruby 根据yml文件设置定期调用函数。(heroku证明),ruby,heroku,cron,job-scheduling,rufus-scheduler,Ruby,Heroku,Cron,Job Scheduling,Rufus Scheduler,我正在开发一个应用程序,它将读取存储在yaml文件中的rss提要列表,并在提要中有新项目时向Hipchat发送消息 下面是myfeeds.yml文件的结构 feeds: feed_name: url: poll_interval: 30 #in seconds hipchat_room: hipchat_color: hipchat_from: hipchat_nofiy: 我希望每个提要在系统检查新项目时有不同的轮询间隔 我的问题是:如何
feeds:
feed_name:
url:
poll_interval: 30 #in seconds
hipchat_room:
hipchat_color:
hipchat_from:
hipchat_nofiy:
我希望每个提要在系统检查新项目时有不同的轮询间隔
我的问题是:如何在代码中处理轮询间隔。每次达到该间隔时,我都需要调用该方法来处理提要,并且每个提要的时间可能不同。
我应该用像鲁弗斯一样的东西吗
我希望我的应用程序简单,能够在Heroku免费层中运行而不会出现问题
多谢各位
编辑:我还没有太多的代码。我正在计划申请。我是这样想的:
app.rb
我想我可以用rufus调度程序gem,但如果我有很多feed,我不确定heroku会如何处理它。如果我理解正确,gem会为每个提要创建一个线程。很难说您如何处理轮询间隔,因为我们看不到您编写的代码。使用示例代码更新了post。默认情况下,Rufus-scheduler最多有77个工作线程池。这些工作线程用于运行触发的作业。因此,如果您一次调度少于78个提要,那么每个提要的一个线程将是正确的。
# reads the feeds
feeds_list = YAML.load(File.read("feeds.yml"))
# iterates each feed and creates a feed object.
feeds_list['feeds'].each do |f|
feed = HipchatRssNotify::Feed.new f
# calls some method to process that particular feed.
# The call should be called periodically based on the feed poll_interval.
feed_processor.process(feed)
end