Class: Rpush::Daemon::Apnsp8::Delivery

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

Constant Summary collapse

RETRYABLE_CODES =
[ 429, 500, 503 ]
CLIENT_JOIN_TIMEOUT =
60
DEFAULT_MAX_CONCURRENT_STREAMS =
100

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, token_provider, batch) ⇒ Delivery

Returns a new instance of Delivery.



13
14
15
16
17
18
19
# File 'lib/rpush/daemon/apnsp8/delivery.rb', line 13

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

Instance Method Details

#performObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rpush/daemon/apnsp8/delivery.rb', line 21

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, HTTP2::Error::StreamLimitExceeded => error
  # TODO restart connection when StreamLimitExceeded
  mark_batch_retryable(Time.now + 10.seconds, error)
  raise
rescue StandardError => error
  mark_batch_failed(error)
  raise
ensure
  @batch.all_processed
end