2023-01-09 16:02:06 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: email_events
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# method :string not null
|
|
|
|
# processed_at :datetime
|
|
|
|
# status :string not null
|
|
|
|
# subject :string not null
|
|
|
|
# to :string not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
class EmailEvent < ApplicationRecord
|
|
|
|
enum status: {
|
2023-01-09 23:16:14 +01:00
|
|
|
dispatched: 'dispatched',
|
|
|
|
dispatch_error: 'dispatch_error'
|
2023-01-09 16:02:06 +01:00
|
|
|
}
|
2023-01-09 23:16:14 +01:00
|
|
|
|
2023-01-09 17:05:38 +01:00
|
|
|
class << self
|
|
|
|
def create_from_message!(message, status:)
|
2023-01-10 13:58:30 +01:00
|
|
|
to = message.to || ["unset"] # no recipients when error occurs *before* setting to: in the mailer
|
|
|
|
|
|
|
|
to.each do |recipient|
|
2023-01-09 17:05:38 +01:00
|
|
|
EmailEvent.create!(
|
2023-01-10 15:47:00 +01:00
|
|
|
to: recipient,
|
2023-01-17 16:46:54 +01:00
|
|
|
subject: message.subject || "",
|
2023-01-09 17:05:38 +01:00
|
|
|
processed_at: message.date,
|
|
|
|
method: ActionMailer::Base.delivery_methods.key(message.delivery_method.class),
|
|
|
|
status:
|
|
|
|
)
|
|
|
|
rescue StandardError => error
|
|
|
|
Sentry.capture_exception(error, extra: { subject: message.subject, status: })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-01-09 16:02:06 +01:00
|
|
|
end
|