Class: Webhookdb::WebhookSubscription::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/webhook_subscription/delivery.rb

Overview

Represents the attempted delivery of a rowupsert to a particular webhook subscription. See WebhookSubscription for more details.

Defined Under Namespace

Classes: Attempt

Instance Method Summary collapse

Instance Method Details

#add_attempt(status:, at: Time.now) ⇒ Object

Add an attempt to this instance.



20
21
22
23
24
25
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 20

def add_attempt(status:, at: Time.now)
  self.attempt_timestamps << at
  self.modified!(:attempt_timestamps)
  self.attempt_http_response_statuses << status
  self.modified!(:attempt_http_response_statuses)
end

#attempt_countObject

Fast path for getting the total attempt count.



35
36
37
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 35

def attempt_count
  return self.attempt_timestamps.length
end

#attempt_deliveryObject

See WebhookSubhscription#attempt_delivery



15
16
17
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 15

def attempt_delivery
  self.webhook_subscription.attempt_delivery(self)
end

#attemptsObject

Create a list of Attempt instances.



28
29
30
31
32
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 28

def attempts
  return self.attempt_timestamps.
      zip(self.attempt_http_response_statuses).
      map { |(at, status)| Attempt.new(at, status) }
end

#latest_attemptObject

Return the latest attempt, or nil if there have been no attempts.



40
41
42
43
44
45
46
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 40

def latest_attempt
  cnt = self.attempt_count
  return nil if cnt.zero?
  ts = self.attempt_timestamps[cnt - 1]
  status = self.attempt_http_response_statuses[cnt - 1]
  return Attempt.new(ts, status)
end

#latest_attempt_statusObject

One of ‘pending’ (no attempts), ‘success’, or ‘error’.



49
50
51
52
53
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 49

def latest_attempt_status
  att = self.latest_attempt
  return "pending" if att.nil?
  return att.success ? "success" : "error"
end