Class: SesDashboard::WebhookEventPersistor
- Inherits:
-
Object
- Object
- SesDashboard::WebhookEventPersistor
- Defined in:
- app/services/ses_dashboard/webhook_event_persistor.rb
Overview
Persists a processed SNS event (from WebhookProcessor::Result) to the database.
Separating parsing (WebhookProcessor, in lib/) from persistence (here) keeps the parser free of Rails/AR dependencies and fully unit-testable.
Instance Method Summary collapse
-
#initialize(project, result) ⇒ WebhookEventPersistor
constructor
A new instance of WebhookEventPersistor.
- #persist ⇒ Object
Constructor Details
#initialize(project, result) ⇒ WebhookEventPersistor
Returns a new instance of WebhookEventPersistor.
8 9 10 11 |
# File 'app/services/ses_dashboard/webhook_event_persistor.rb', line 8 def initialize(project, result) @project = project @result = result end |
Instance Method Details
#persist ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/ses_dashboard/webhook_event_persistor.rb', line 13 def persist return if @result..blank? ActiveRecord::Base.transaction do email = find_or_create_email create_event(email) update_email_state(email) end rescue ActiveRecord::RecordInvalid => e log_error("Failed to persist webhook event: #{e.}") end |