lib/rapnd/daemon.rb in rapnd-0.3.1 vs lib/rapnd/daemon.rb in rapnd-0.4.0
- old
+ new
@@ -48,27 +48,32 @@
def run!
loop do
begin
message = @redis.blpop(self.queue, 1)
- send_message(message) if message
+ if message
+ notification = Rapnd::Notification.new(Marshal.load(message.last))
+ self.connect! unless self.connected
+ @logger.info "Sending #{notification.device_token}: #{notification.json_payload}"
+ self.apple.write(notification.to_bytes)
+ end
rescue Exception => e
if e.class == Interrupt || e.class == SystemExit
@logger.info "Shutting down..."
exit(0)
end
self.connect!
- send_message(message) if message
+ if notification
+ @logger.info "Trying again for: #{notification.json_payload}"
+ self.apple.write(notification.to_bytes)
+ end
Airbrake.notify(e, {:environment_name => self.queue }) if @airbrake
@logger.error "Encountered error: #{e}"
end
end
end
end
def send_message(message)
- notification = Rapnd::Notification.new(Marshal.load(message.last))
- self.connect! unless self.connected
- @logger.info "Sending Apple: #{notification.json_payload}"
- self.apple.write(notification.to_bytes)
+
end
end
\ No newline at end of file