lib/rapnd/daemon.rb in rapnd-0.3.0 vs lib/rapnd/daemon.rb in rapnd-0.3.1

- old
+ new

@@ -48,24 +48,27 @@ def run! loop do begin message = @redis.blpop(self.queue, 1) - if 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 + send_message(message) if message rescue Exception => e if e.class == Interrupt || e.class == SystemExit @logger.info "Shutting down..." exit(0) end self.connect! + send_message(message) if message 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