Class: Pushr::Daemon::ApnsSupport::FeedbackReceiver
- Inherits:
-
Object
- Object
- Pushr::Daemon::ApnsSupport::FeedbackReceiver
- Defined in:
- lib/pushr/daemon/apns_support/feedback_receiver.rb
Constant Summary collapse
- FEEDBACK_TUPLE_BYTES =
38
Instance Method Summary collapse
- #check_every_configuration ⇒ Object
- #check_for_feedback(config) ⇒ Object
-
#initialize(configuration, _) ⇒ FeedbackReceiver
constructor
A new instance of FeedbackReceiver.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(configuration, _) ⇒ FeedbackReceiver
Returns a new instance of FeedbackReceiver.
7 8 9 10 |
# File 'lib/pushr/daemon/apns_support/feedback_receiver.rb', line 7 def initialize(configuration, _) @configuration = configuration @interruptible_sleep = InterruptibleSleep.new end |
Instance Method Details
#check_every_configuration ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/pushr/daemon/apns_support/feedback_receiver.rb', line 28 def check_every_configuration Pushr::Configuration.all.each do |config| if config.enabled == true && config.class == Pushr::ConfigurationApns Pushr::Daemon.logger.info("[#{config.app}: Checking for feedback") check_for_feedback(config) end end end |
#check_for_feedback(config) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pushr/daemon/apns_support/feedback_receiver.rb', line 37 def check_for_feedback(config) connection = nil begin connection = ConnectionApns.new(config) connection.connect while tuple = connection.read(FEEDBACK_TUPLE_BYTES) , device = parse_tuple(tuple) create_feedback(config, connection, , device) end rescue StandardError => e Pushr::Daemon.logger.error(e) ensure connection.close if connection end end |
#start ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/pushr/daemon/apns_support/feedback_receiver.rb', line 12 def start @thread = Thread.new do loop do break if @stop check_every_configuration @interruptible_sleep.sleep @configuration.feedback_poll end end end |
#stop ⇒ Object
22 23 24 25 26 |
# File 'lib/pushr/daemon/apns_support/feedback_receiver.rb', line 22 def stop @stop = true @interruptible_sleep.interrupt @thread.join if @thread end |