2018-12-14 05:06:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-12 19:34:05 -05:00
|
|
|
# A newly received `InboundEmail` will not be routed synchronously as part of ingress controller's receival.
|
|
|
|
# Instead, the routing will be done asynchronously, using a `RoutingJob`, to ensure maximum parallel capacity.
|
|
|
|
#
|
|
|
|
# By default, all newly created `InboundEmail` records that have the status of `pending`, which is the default,
|
|
|
|
# will be scheduled for automatic, deferred routing.
|
2018-09-28 15:19:43 -04:00
|
|
|
module ActionMailbox::InboundEmail::Routable
|
2018-09-19 19:40:56 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2018-10-17 10:38:51 -04:00
|
|
|
after_create_commit :route_later, if: :pending?
|
2018-09-19 19:40:56 -04:00
|
|
|
end
|
|
|
|
|
2018-12-12 19:34:05 -05:00
|
|
|
# Enqueue a `RoutingJob` for this `InboundEmail`.
|
2018-09-28 14:32:44 -04:00
|
|
|
def route_later
|
2018-09-28 15:19:43 -04:00
|
|
|
ActionMailbox::RoutingJob.perform_later self
|
2018-09-28 14:32:44 -04:00
|
|
|
end
|
2018-10-01 15:42:32 -04:00
|
|
|
|
2018-12-12 19:34:05 -05:00
|
|
|
# Route this `InboundEmail` using the routing rules declared on the `ApplicationMailbox`.
|
2018-10-01 15:42:32 -04:00
|
|
|
def route
|
|
|
|
ApplicationMailbox.route self
|
|
|
|
end
|
2018-09-19 19:40:56 -04:00
|
|
|
end
|