I have a model Resend in my Ruby project, it contains content and status columns.
What is the best/fastest way to consume all the records with status 0 using EventMachine ?
I want to create a simple worker that try to find records with status==0 every period ( like every 5 mins)
I'm still new to EventMachine and couldn't find so much examples of how to deal with DB.
So far I made something like the following but not sure if it's the best implementation :
$ROOT_PATH ||= File.expand_path("#{File.dirname __FILE__}")
require "rubygems"
require 'eventmachine'
require 'em-http'
require "#{$ROOT_PATH}/app/models/resend.rb"
EventMachine.run do
EM.add_periodic_timer(5) do
Resend.active.each do |msg|
http = EventMachine::HttpRequest.new($RECEIVER_URL).post :body => {:message => msg.content }
http.callback { msg.update_status! }
end
end
end
Any help would be highly appreciated