Class: Fuik::WebhookEvent
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Fuik::WebhookEvent
- Includes:
- Filterable
- Defined in:
- app/models/fuik/webhook_event.rb,
app/models/fuik/webhook_event/filterable.rb
Defined Under Namespace
Modules: Filterable
Class Method Summary collapse
Instance Method Summary collapse
-
#failed!(error = nil) ⇒ Boolean
Mark the event as failed and record the error.
- #payload ⇒ Object
- #process_later! ⇒ Object
-
#processed! ⇒ Boolean
Mark the event as successfully processed.
-
#retry! ⇒ Boolean
Retry a failed event.
Class Method Details
.event_class_for(provider, event_type) ⇒ Object
7 8 9 |
# File 'app/models/fuik/webhook_event.rb', line 7 def self.event_class_for(provider, event_type) "#{provider.camelize}::#{event_type.tr("./:-[]", "_").camelize}".safe_constantize end |
Instance Method Details
#failed!(error = nil) ⇒ Boolean
Mark the event as failed and record the error.
36 37 38 |
# File 'app/models/fuik/webhook_event.rb', line 36 def failed!(error = nil) update!(status: "failed", error: error.to_s) end |
#payload ⇒ Object
18 19 20 21 22 |
# File 'app/models/fuik/webhook_event.rb', line 18 def payload @payload ||= JSON.parse(body) rescue JSON::ParserError {} end |
#process_later! ⇒ Object
53 54 55 56 57 |
# File 'app/models/fuik/webhook_event.rb', line 53 def process_later! event_class = self.class.event_class_for(provider, event_type) Fuik.webhook_processing_job_class.constantize.perform_later(event_class.name, self) if event_class end |
#processed! ⇒ Boolean
Mark the event as successfully processed.
27 28 29 |
# File 'app/models/fuik/webhook_event.rb', line 27 def processed! update!(status: "processed") end |
#retry! ⇒ Boolean
Retry a failed event. Resets its status back to pending, clears the error, and enqueues processing via WebhookProcessingJob.
46 47 48 49 50 51 |
# File 'app/models/fuik/webhook_event.rb', line 46 def retry! raise "Can only retry failed events" unless failed? update!(status: "pending", error: nil) process_later! end |