lib/rapnd/daemon.rb in rapnd-0.1.8 vs lib/rapnd/daemon.rb in rapnd-0.1.9

- old
+ new

@@ -20,11 +20,11 @@ @redis = Redis.new(:host => options[:redis_host], :port => options[:redis_port]) @queue = options[:queue] @cert = options[:cert] @host = options[:host] - puts 'Initialized!' + puts "Listening on queue: #{self.queue}" end def connect! puts 'Connecting...' @context = OpenSSL::SSL::SSLContext.new @@ -41,14 +41,16 @@ return @sock, @ssl end def run! - notification = Rapnd::Notification.new(Marshal.load(@redis.blpop(self.queue, 0).last)) - puts 'Notification popped.' - self.connect! unless self.connected - puts "Sending Apple: #{notification.json_payload}" - self.apple.write(notification.to_bytes) + message = @redis.blpop(self.queue, 1) + if message + notification = Rapnd::Notification.new(Marshal.load(message.last)) + self.connect! unless self.connected + puts "Sending Apple: #{notification.json_payload}" + self.apple.write(notification.to_bytes) + end self.run! end end end \ No newline at end of file