Skip to content

Instantly share code, notes, and snippets.

@railsfactory
Created September 15, 2009 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save railsfactory/187608 to your computer and use it in GitHub Desktop.
Save railsfactory/187608 to your computer and use it in GitHub Desktop.
module Handler
def file_modified
puts "#{path} modified"
lines = File.read(path)
lines.each do|line|
#puts "I read this line: #{line.chomp}"
url = line.chomp
http = EventMachine::HttpRequest.new(url).get #.get( :timeout => 10)
http.callback {
http.response_header.status
puts url
pp http.response_header
#p http.response
filename = Digest::MD5.hexdigest(http.uri.to_s)
File.open('./data/'+ filename, 'w') { |f| f.write(http.response) }
pp filename
#else
# puts "#{http.inspect} failed"
#end
}
end
end
def file_moved
puts "#{path} moved"
end
def file_deleted
puts "#{path} deleted"
end
def unbind
puts "#{path} monitoring ceased"
end
end
EventMachine.kqueue=true
EventMachine.run {
EventMachine.watch_file($urlfile, Handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment