异步运行Activerecord

时间:2012-03-31 21:20:06

标签: ruby-on-rails ruby ruby-on-rails-3 activerecord asynchronous

我有一些工作人员从队列(rabbitmq)获取数据,而在工作者内部我想使用activerecord异步创建记录,我当前的实现类似于:

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 

我想以异步方式运行记录以提高性能,这里有任何建议吗?

1 个答案:

答案 0 :(得分:0)

您可能需要查看delayed_job:

https://github.com/collectiveidea/delayed_job