diff options
author | George Claghorn <george@basecamp.com> | 2018-10-17 10:38:51 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-10-17 10:38:51 -0400 |
commit | 8973fbcf08fcbfb7af8ad9fd9465ff3c2de06437 (patch) | |
tree | 040e685506501fcc5ddf185748a34d6497ab3b0e /app/models/action_mailbox | |
parent | 47445511862a4c9979fb46889011edf585391091 (diff) | |
download | rails-8973fbcf08fcbfb7af8ad9fd9465ff3c2de06437.tar.gz rails-8973fbcf08fcbfb7af8ad9fd9465ff3c2de06437.tar.bz2 rails-8973fbcf08fcbfb7af8ad9fd9465ff3c2de06437.zip |
Simplify incineration
Diffstat (limited to 'app/models/action_mailbox')
4 files changed, 12 insertions, 21 deletions
diff --git a/app/models/action_mailbox/inbound_email.rb b/app/models/action_mailbox/inbound_email.rb index f2589d7429..7d1a36b705 100644 --- a/app/models/action_mailbox/inbound_email.rb +++ b/app/models/action_mailbox/inbound_email.rb @@ -19,4 +19,8 @@ class ActionMailbox::InboundEmail < ActiveRecord::Base def source @source ||= raw_email.download end + + def processed? + delivered? || failed? || bounced? + end end diff --git a/app/models/action_mailbox/inbound_email/incineratable.rb b/app/models/action_mailbox/inbound_email/incineratable.rb index 364231a443..198846422c 100644 --- a/app/models/action_mailbox/inbound_email/incineratable.rb +++ b/app/models/action_mailbox/inbound_email/incineratable.rb @@ -2,27 +2,14 @@ module ActionMailbox::InboundEmail::Incineratable extend ActiveSupport::Concern included do - before_update :remember_to_incinerate_later - after_update_commit :incinerate_later, if: :incinerating_later? + after_update_commit :incinerate_later, if: -> { status_previously_changed? && processed? } + end + + def incinerate_later + ActionMailbox::IncinerationJob.schedule self end def incinerate Incineration.new(self).run end - - private - # TODO: Use enum change tracking once merged into Active Support - def remember_to_incinerate_later - if status_changed? && (delivered? || bounced? || failed?) - @incinerating_later = true - end - end - - def incinerating_later? - @incinerating_later ||= false - end - - def incinerate_later - ActionMailbox::InboundEmail::IncinerationJob.schedule(self) - end end diff --git a/app/models/action_mailbox/inbound_email/incineratable/incineration.rb b/app/models/action_mailbox/inbound_email/incineratable/incineration.rb index ab9311edfb..801cc0c8b9 100644 --- a/app/models/action_mailbox/inbound_email/incineratable/incineration.rb +++ b/app/models/action_mailbox/inbound_email/incineratable/incineration.rb @@ -4,7 +4,7 @@ class ActionMailbox::InboundEmail::Incineratable::Incineration end def run - @inbound_email.destroy if due? && processed? + @inbound_email.destroy! if due? && processed? end private @@ -13,6 +13,6 @@ class ActionMailbox::InboundEmail::Incineratable::Incineration end def processed? - @inbound_email.delivered? || @inbound_email.bounced? || @inbound_email.failed? + @inbound_email.processed? end end diff --git a/app/models/action_mailbox/inbound_email/routable.rb b/app/models/action_mailbox/inbound_email/routable.rb index 48b357af45..8f5b0ddd39 100644 --- a/app/models/action_mailbox/inbound_email/routable.rb +++ b/app/models/action_mailbox/inbound_email/routable.rb @@ -2,7 +2,7 @@ module ActionMailbox::InboundEmail::Routable extend ActiveSupport::Concern included do - after_create_commit :route_later, if: ->(inbound_email) { inbound_email.pending? } + after_create_commit :route_later, if: :pending? end def route_later |