Ruby daemons and frequency

Posted by mplacona on Stack Overflow See other posts from Stack Overflow or by mplacona
Published on 2010-03-21T22:36:24Z Indexed on 2010/03/21 22:41 UTC
Read the original article Hit count: 669

Filed under:
|
|

Hi, 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 never happen exactly every 5 minutes, and I'll see variations of 4-6 minutes.

thanks in advance

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails