Class: Rapns::Daemon::FeedbackReceiver

Inherits:
Object
  • Object
show all
Extended by:
InterruptibleSleep
Defined in:
lib/rapns/daemon/feedback_receiver.rb

Constant Summary collapse

FEEDBACK_TUPLE_BYTES =
38

Class Method Summary collapse

Methods included from InterruptibleSleep

interrupt_sleep, interruptible_sleep

Class Method Details

.check_for_feedbackObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rapns/daemon/feedback_receiver.rb', line 24

def self.check_for_feedback
  connection = nil
  begin
    host = Rapns::Daemon.configuration.feedback.host
    port = Rapns::Daemon.configuration.feedback.port
    connection = Connection.new("FeedbackReceiver", host, port)
    connection.connect

    while tuple = connection.read(FEEDBACK_TUPLE_BYTES)
      timestamp, device_token = parse_tuple(tuple)
      create_feedback(timestamp, device_token)
    end
  rescue StandardError => e
    Rapns::Daemon.logger.error(e)
  ensure
    connection.close if connection
  end
end

.startObject



8
9
10
11
12
13
14
15
16
# File 'lib/rapns/daemon/feedback_receiver.rb', line 8

def self.start
  @thread = Thread.new do
    loop do
      break if @stop
      check_for_feedback
      interruptible_sleep Rapns::Daemon.configuration.feedback.poll
    end
  end
end

.stopObject



18
19
20
21
22
# File 'lib/rapns/daemon/feedback_receiver.rb', line 18

def self.stop
  @stop = true
  interrupt_sleep
  @thread.join if @thread
end