From c382d9b1800019010afcb441558cf5ebef4acbd3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Sep 2018 16:54:49 -0700 Subject: Extract method to encapsulate status tracking on inbound email --- lib/action_mailroom/mailbox.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/action_mailroom/mailbox.rb b/lib/action_mailroom/mailbox.rb index 3518449794..85b6662136 100644 --- a/lib/action_mailroom/mailbox.rb +++ b/lib/action_mailroom/mailbox.rb @@ -20,16 +20,12 @@ class ActionMailroom::Mailbox end def perform_processing - inbound_email.processing! - - run_callbacks :process do - process + track_status_of_inbound_email do + run_callbacks :process do + process + end end - - inbound_email.delivered! rescue => exception - inbound_email.failed! - # TODO: Include a reference to the inbound_email in the exception raised so error handling becomes easier rescue_with_handler(exception) || raise end @@ -37,4 +33,14 @@ class ActionMailroom::Mailbox def process # Overwrite in subclasses end + + private + def track_status_of_inbound_email + inbound_email.processing! + yield + inbound_email.delivered! + rescue => exception + inbound_email.failed! + raise + end end -- cgit v1.2.3