bin/racoon-firehose in racoon-0.5.0 vs bin/racoon-firehose in racoon-0.6.0
- old
+ new
@@ -4,10 +4,12 @@
require 'getoptlong'
require 'rubygems'
require 'daemons'
require 'racoon'
require 'csv'
+require 'yaml'
+require 'zmqmachine'
def usage
puts "Usage: racoon-firehose [switches]"
puts " --pid </var/run/racoon-firehose.pid> the path to store the pid"
puts " --log </var/log/racoon-firehosed.log> the path to store the log"
@@ -52,8 +54,30 @@
Racoon::Config.logger = Logger.new(@log_file)
if daemon
daemonize
else
- puts "Starting racoon worker."
+ puts "Starting racoon firehose."
end
-Racoon::Firehose.new.start!
+
+ZM::Reactor.new(:firehose).run do |context|
+ firehose = Racoon::Firehose.new(context) do |feedback_record|
+ Racoon::Config.logger.info "[Feedback] Time: #{feedback_record[:feedback_at]} Device: #{feedback_record[:device_token]} Length: #{feedback_record[:length]}"
+ end
+ context.pull_socket(firehose)
+
+ context.periodical_timer(28800) do
+ firehose.connections.each_pair do |key, data|
+ begin
+ project = data[:project]
+ uri = "gateway.#{project[:sandbox] ? 'sandbox.' : ''}push.apple.com"
+ feedback = Racoon::APNS::FeedbackConnection.new(data[:certificate], uri)
+ feedback.connect!
+ feedback.read.each do |record|
+ @feedback_callback.call(record) if @feedback_callback
+ end
+ rescue Errno::EPIPE, OpenSSL::SSL::SSLError, Errno::ECONNRESET
+ feedback.disconnect!
+ end
+ end
+ end
+end.join