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 ]
CLIENT_JOIN_TIMEOUT =
60

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.



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

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

Instance Method Details

#performObject



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

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

  # Send all preprocessed requests at once
  @client.join(timeout: CLIENT_JOIN_TIMEOUT)
rescue NetHttp2::AsyncRequestTimeout => error
  mark_batch_retryable(Time.now + 10.seconds, error)
  @client.close
  raise
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