Class: Rpush::Daemon::Apns2::Delivery

Inherits:
Delivery
  • Object
show all
Defined in:
lib/rpush/daemon/apns2/delivery.rb

Constant Summary collapse

RETRYABLE_CODES =
[ 429, 500, 503 ]

Instance Method Summary collapse

Methods inherited from Delivery

#mark_batch_delivered, #mark_batch_failed, #mark_batch_retryable, #mark_delivered, #mark_failed, #mark_retryable, #mark_retryable_exponential

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Methods included from Reflectable

#reflect

Constructor Details

#initialize(app, http2_client, batch) ⇒ Delivery

Returns a new instance of Delivery.



11
12
13
14
15
# File 'lib/rpush/daemon/apns2/delivery.rb', line 11

def initialize(app, http2_client, batch)
  @app = app
  @client = http2_client
  @batch = batch
end

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpush/daemon/apns2/delivery.rb', line 17

def perform
  @client.on(:error) { |err| mark_batch_retryable(Time.now + 10.seconds, err) }

  @batch.each_notification do |notification|
    prepare_async_post(notification)
  end

  # Send all preprocessed requests at once
  @client.join
rescue Errno::ECONNREFUSED, SocketError => error
  mark_batch_retryable(Time.now + 10.seconds, error)
  raise
rescue StandardError => error
  mark_batch_failed(error)
  raise
ensure
  @batch.all_processed
end