Class: Studio::EmailDelivery
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Studio::EmailDelivery
- Defined in:
- app/models/studio/email_delivery.rb
Class Method Summary collapse
- .available? ⇒ Boolean
- .deliver(mailer, action, *args, to:, user: nil, **kwargs) ⇒ Object
- .resend_unsent! ⇒ Object
Instance Method Summary collapse
Class Method Details
.available? ⇒ Boolean
10 11 12 13 14 |
# File 'app/models/studio/email_delivery.rb', line 10 def self.available? connection.data_source_exists?(table_name) rescue ActiveRecord::ActiveRecordError, NoMethodError false end |
.deliver(mailer, action, *args, to:, user: nil, **kwargs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/studio/email_delivery.rb', line 16 def self.deliver(mailer, action, *args, to:, user: nil, **kwargs) record = create!( mailer: mailer.to_s, action: action.to_s, email_key: "#{mailer}##{action}", to: to.to_s, user: user, args: ActiveJob::Arguments.serialize(args), kwargs: ActiveJob::Arguments.serialize([kwargs]).first ) Studio::EmailDeliveryJob.perform_later(record.id) unless Studio.local_email_capture? record end |
.resend_unsent! ⇒ Object
43 44 45 |
# File 'app/models/studio/email_delivery.rb', line 43 def self.resend_unsent! unsent.find_each { |delivery| Studio::EmailDeliveryJob.perform_later(delivery.id) } end |
Instance Method Details
#deliver_now! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/studio/email_delivery.rb', line 30 def deliver_now! return if sent? return update!(error: "local email capture enabled; not sent") if Studio.local_email_capture? pos = ActiveJob::Arguments.deserialize(args) kw = ActiveJob::Arguments.deserialize([kwargs]).first.symbolize_keys mailer.constantize.public_send(action, *pos, **kw).deliver_now update!(sent: true, sent_at: Time.current, error: nil) rescue StandardError => e update(error: e..to_s.first(500)) raise end |