我在我的项目中有一个模型重新发送,它包含内容和状态列。
使用EventMachine消耗状态为0的所有记录的最佳/最快方法是什么?
我想要创建一个简单的工作人员,它尝试每段时间用status==0查找记录(比如每隔5分钟)
我对EventMachine还不熟悉,也找不到很多如何处理DB的例子。
到目前为止,我做了如下内容,但不确定它是否是最佳实现:
$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任何帮助都将不胜感激。
https://stackoverflow.com/questions/13806433
复制相似问题