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