开发者

Ruby daemons and frequency

I've written this ruby daemon, and was wondering if somebody could have a look at it, and tell me if the approach I've taken is correct.

#!/usr/bin/env ruby

require 'logger'  

# You might want to change this
ENV["RAILS_ENV"] ||= "production"

require File.dirname(__FILE__) + "/../../config/environment"

$running = true
Signal.trap("TERM") do 
  $running = false
end

service = Post.new('http://feed.com/feeds')
logger  = Logger.new('reader.log')

while($running) do
  # Log my calls
  logger.info "Run at #{Time.now}"

  service.update_from_feed_continuously
  # only run it every 5 minutes or so
  sleep 300
end

I feel like this last loop is not quite the right thing to do, and can be memory intensive, but I'm not sure. Also, the 5 minutes seem to ne开发者_运维问答ver happen exactly every 5 minutes, and I'll see variations of 4-6 minutes.

thanks in advance


There was a quite interesting article about a year ago:

Ruby Daemons: Verifying Good Behavior


The time discrepancy could come from how long service.update_from_feed_continuously takes. Is this a non-trivial computation or one that relies on a web service (their added delays could dwarf many client-side computations).

Not sure about the structure of the rest though, sorry!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜