aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/action_mailbox/inbound_email/incineratable.rb
blob: fb2461cf50ffb23df5bc59767db5857e61d26a67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

# Ensure that the `InboundEmail` is automatically scheduled for later incineration if the status has been
# changed to `processed`. The later incineration will be invoked at the time specified by the 
# `ActionMailbox.incinerate_after` time using the `IncinerationJob`.
module ActionMailbox::InboundEmail::Incineratable
  extend ActiveSupport::Concern

  included do
    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
end