Running Activerecord asynchronously
I have a worker that accepts data from a queue (rabbitmq) and inside the worker I want to create records with activerecord asynchronously, my current implementation is something like:
require "rubygems"
require "amqp"
require 'eventmachine'
require 'em-http'
AMQP.start(:host => $AMQP_URL) do |connection|
@queue ||= AMQP::Channel.new(connection).queue("results")
@queue.subscribe do |body|
EventMachine::HttpRequest.new('http://someurl').post :body => {:message => body }
Record.create!(:name => body)
end
end
I want to run Recording asynchronously to improve performance, any recommendations here?
+3
source to share