尝试在Rails中使用GroupMe gem EM- C2DM,https://github.com/groupme/em-c2dm,一个使用事件机器的GoogleRuby库。我知道它应该可以在Heroku上工作,因为有一个特定于Heroku的配置,但是我似乎无法让它运行。
我正在通过Resque Worker执行,并且worker工作正常,并被排队和调用。但是,它无法通过身份验证,并且从不报告推送通知的响应。它似乎永远不会结束。
module PushAndroid
require "eventmachine"
require "em-c2dm"
@queue = :android_push
def self.perform(opts)
puts "entering android push"
EM.next_tick do
EM::C2DM.authenticate(ENV["C2DM_EMAIL"], ENV["C2DM_PASSWORD"])
@push = Push.find(opts['push_id'])
message = "Message #{@push.title}"
push_id = "#{@push.id}"
opts['tokens'].each{ |token|
EM::C2DM.push(token, :message => message, :push_id => push_id) do |response|
if response.success?
puts "success! id=#{response.id}" # ID of sent message
else
puts "response:"
puts response.inspect
#case response.error
#when "InvalidToken"
# reauthenticate
#when "InvalidRegistration"
# clear our registration id
#when "RetryAfter"
# pause sending for response.retry_after seconds
#end
end
end
}
end
end
end
我也尝试过在不使用EM::next_tick或EM.next_tick的情况下使用它,它通过了身份验证,但是不会推送任何东西,也不会返回响应或任何东西。事实上,它从来没有进入过EM::next_tick。
你有什么办法让它工作吗?这是在Heroku上,使用Rails 3.1.1和Thin
在我的Gemfile.lock上:
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
eventmachine (1.0.0.beta.4)
em-apn (0.0.3)
eventmachine (>= 1.0.0.beta.3)
yajl-ruby (>= 0.8.2)
em-http-request (1.0.2)
addressable (>= 2.2.3)
cookiejar
em-socksify
eventmachine (>= 1.0.0.beta.4)
http_parser.rb (>= 0.5.3)
em-socksify (0.2.0)
eventmachine (>= 1.0.0.beta.4)
remote: git://github.com/groupme/em-c2dm.git
revision: 2d853ff771908785f23b8c64fa5d5508b4eba40a
specs:
em-c2dm (0.0.1)
em-http-request (>= 1.0.0.beta.4)
eventmachine (>= 1.0.0.beta.3)
uuid
发布于 2012-06-07 20:26:39
把它放在EM.run中已经解决了这个问题。我猜工作人员不会连接到Thin,因此需要运行自己的反应堆
https://stackoverflow.com/questions/10924534
复制相似问题