Class: Upkeep::Delivery::Transport::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/upkeep/delivery/transport.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subscriber_id:, adapter:, max_queue_size:, retry_limit:) ⇒ Connection

Returns a new instance of Connection.



53
54
55
56
57
58
59
# File 'lib/upkeep/delivery/transport.rb', line 53

def initialize(subscriber_id:, adapter:, max_queue_size:, retry_limit:)
  @subscriber_id = subscriber_id
  @adapter = adapter
  @max_queue_size = max_queue_size
  @retry_limit = retry_limit
  @queue = []
end

Instance Attribute Details

#subscriber_idObject (readonly)

Returns the value of attribute subscriber_id.



51
52
53
# File 'lib/upkeep/delivery/transport.rb', line 51

def subscriber_id
  @subscriber_id
end

Instance Method Details

#deliver(envelope) ⇒ Object



61
62
63
# File 'lib/upkeep/delivery/transport.rb', line 61

def deliver(envelope)
  deliver_envelope(envelope, attempts: 0)
end

#disconnectObject



72
73
74
75
76
# File 'lib/upkeep/delivery/transport.rb', line 72

def disconnect
  dropped = @queue.size
  @queue = []
  dropped
end

#queue_depthObject



78
79
80
# File 'lib/upkeep/delivery/transport.rb', line 78

def queue_depth
  @queue.size
end

#retry_pendingObject



65
66
67
68
69
70
# File 'lib/upkeep/delivery/transport.rb', line 65

def retry_pending
  pending = @queue
  @queue = []

  pending.map { |item| deliver_envelope(item.envelope, attempts: item.attempts) }
end