Class: Webhookdb::WebhookSubscription::Delivery
- Inherits:
-
Object
- Object
- Webhookdb::WebhookSubscription::Delivery
- 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
-
#add_attempt(status:, at: Time.now) ⇒ Object
Add an attempt to this instance.
-
#attempt_count ⇒ Object
Fast path for getting the total attempt count.
-
#attempt_delivery ⇒ Object
See WebhookSubhscription#attempt_delivery.
-
#attempts ⇒ Object
Create a list of Attempt instances.
-
#latest_attempt ⇒ Object
Return the latest attempt, or nil if there have been no attempts.
-
#latest_attempt_status ⇒ Object
One of ‘pending’ (no attempts), ‘success’, or ‘error’.
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. << at self.modified!(:attempt_timestamps) self.attempt_http_response_statuses << status self.modified!(:attempt_http_response_statuses) end |
#attempt_count ⇒ Object
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..length end |
#attempt_delivery ⇒ Object
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 |
#attempts ⇒ Object
Create a list of Attempt instances.
29 30 31 32 33 |
# File 'lib/webhookdb/webhook_subscription/delivery.rb', line 29 def attempts return self.. zip(self.attempt_http_response_statuses). map { |(at, status)| Attempt.new(at, status) } end |
#latest_attempt ⇒ Object
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.[cnt - 1] status = self.attempt_http_response_statuses[cnt - 1] return Attempt.new(ts, status) end |
#latest_attempt_status ⇒ Object
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 |