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.



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

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.



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

def attempt_count
  return self.attempt_timestamps.length
end

#attempt_deliveryObject

See WebhookSubhscription#attempt_delivery



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

def attempt_delivery
  self.webhook_subscription.attempt_delivery(self)
end

#attemptsObject

Create a list of Attempt instances.



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

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.



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

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’.



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

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