mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simplify incineration
This commit is contained in:
parent
4744551186
commit
8973fbcf08
6 changed files with 16 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
class ActionMailbox::InboundEmail::IncinerationJob < ApplicationJob
|
||||
class ActionMailbox::IncinerationJob < ApplicationJob
|
||||
queue_as :action_mailbox_incineration
|
||||
|
||||
def self.schedule(inbound_email)
|
|
@ -19,4 +19,8 @@ class ActionMailbox::InboundEmail < ActiveRecord::Base
|
|||
def source
|
||||
@source ||= raw_email.download
|
||||
end
|
||||
|
||||
def processed?
|
||||
delivered? || failed? || bounced?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,7 @@ class ActionMailbox::InboundEmail::IncinerationTest < ActiveSupport::TestCase
|
|||
test "incinerating 30 days after delivery" do
|
||||
freeze_time
|
||||
|
||||
assert_enqueued_with job: ActionMailbox::InboundEmail::IncinerationJob, at: 30.days.from_now do
|
||||
assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
|
||||
create_inbound_email_from_fixture("welcome.eml").delivered!
|
||||
end
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ class ActionMailbox::InboundEmail::IncinerationTest < ActiveSupport::TestCase
|
|||
test "incinerating 30 days after bounce" do
|
||||
freeze_time
|
||||
|
||||
assert_enqueued_with job: ActionMailbox::InboundEmail::IncinerationJob, at: 30.days.from_now do
|
||||
assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
|
||||
create_inbound_email_from_fixture("welcome.eml").bounced!
|
||||
end
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ class ActionMailbox::InboundEmail::IncinerationTest < ActiveSupport::TestCase
|
|||
test "incinerating 30 days after failure" do
|
||||
freeze_time
|
||||
|
||||
assert_enqueued_with job: ActionMailbox::InboundEmail::IncinerationJob, at: 30.days.from_now do
|
||||
assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
|
||||
create_inbound_email_from_fixture("welcome.eml").failed!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue