Class: Webhooks::Outgoing::Delivery
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Webhooks::Outgoing::Delivery
- Defined in:
- app/models/webhooks/outgoing/delivery.rb
Constant Summary collapse
- ATTEMPT_SCHEDULE =
{ 1 => 15.seconds, 2 => 1.minute, 3 => 5.minutes, 4 => 15.minutes, 5 => 1.hour, }
Instance Method Summary collapse
- #attempt_count ⇒ Object
- #deliver ⇒ Object
- #deliver_async ⇒ Object
- #delivered? ⇒ Boolean
- #failed? ⇒ Boolean
-
#label_string ⇒ Object
🚅 add delegations above.
- #max_attempts ⇒ Object
- #name ⇒ Object
- #next_reattempt_delay ⇒ Object
- #still_attempting? ⇒ Boolean
Instance Method Details
#attempt_count ⇒ Object
53 54 55 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 53 def attempt_count delivery_attempts.count end |
#deliver ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 45 def deliver if delivery_attempts.create.attempt touch(:delivered_at) else deliver_async end end |
#deliver_async ⇒ Object
39 40 41 42 43 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 39 def deliver_async if still_attempting? Webhooks::Outgoing::DeliveryJob.set(wait: next_reattempt_delay).perform_later(self) end end |
#delivered? ⇒ Boolean
57 58 59 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 57 def delivered? delivered_at.present? end |
#failed? ⇒ Boolean
66 67 68 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 66 def failed? !(delivered? || still_attempting?) end |
#label_string ⇒ Object
🚅 add delegations above.
31 32 33 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 31 def label_string event.short_uuid end |
#max_attempts ⇒ Object
74 75 76 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 74 def max_attempts ATTEMPT_SCHEDULE.keys.max end |
#name ⇒ Object
70 71 72 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 70 def name event.short_uuid end |
#next_reattempt_delay ⇒ Object
35 36 37 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 35 def next_reattempt_delay ATTEMPT_SCHEDULE[attempt_count] end |
#still_attempting? ⇒ Boolean
61 62 63 64 |
# File 'app/models/webhooks/outgoing/delivery.rb', line 61 def still_attempting? return false if delivered? attempt_count < max_attempts end |