aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailbox/app/models/action_mailbox/inbound_email/routable.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-12-26 11:02:59 -0500
committerGitHub <noreply@github.com>2018-12-26 11:02:59 -0500
commit9b35b9ff417e8ec9888deac1e66c2855677164cd (patch)
tree82dc9a20a23b855f91f743c5029ec7a97a35b824 /actionmailbox/app/models/action_mailbox/inbound_email/routable.rb
parentb5ed468492387d42a44ca6af525d4a274cda756d (diff)
parenta5b2fff64ca0c1fa7be5124f40a251d991c10a85 (diff)
downloadrails-9b35b9ff417e8ec9888deac1e66c2855677164cd.tar.gz
rails-9b35b9ff417e8ec9888deac1e66c2855677164cd.tar.bz2
rails-9b35b9ff417e8ec9888deac1e66c2855677164cd.zip
Merge pull request #34786 from georgeclaghorn/actionmailbox
Import Action Mailbox
Diffstat (limited to 'actionmailbox/app/models/action_mailbox/inbound_email/routable.rb')
-rw-r--r--actionmailbox/app/models/action_mailbox/inbound_email/routable.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/actionmailbox/app/models/action_mailbox/inbound_email/routable.rb b/actionmailbox/app/models/action_mailbox/inbound_email/routable.rb
new file mode 100644
index 0000000000..58d67eb20c
--- /dev/null
+++ b/actionmailbox/app/models/action_mailbox/inbound_email/routable.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+# 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.
+module ActionMailbox::InboundEmail::Routable
+ extend ActiveSupport::Concern
+
+ included do
+ after_create_commit :route_later, if: :pending?
+ end
+
+ # Enqueue a `RoutingJob` for this `InboundEmail`.
+ def route_later
+ ActionMailbox::RoutingJob.perform_later self
+ end
+
+ # Route this `InboundEmail` using the routing rules declared on the `ApplicationMailbox`.
+ def route
+ ApplicationMailbox.route self
+ end
+end