From 8c127ba5da2f2fbe4e04d8fc38debedb451eac33 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 26 Oct 2021 17:51:17 +1100 Subject: [PATCH] Try not abort on exception when we cannot dispatch a message to be processed --- app/Classes/File/Receive.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index c6c366c..6cb2173 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -139,20 +139,27 @@ final class Receive extends Item $queue = ($po->count() > config('app.queue_msgs')); Log::info(sprintf('%s: - Messages will be sent to the queue for processing',self::LOGKEY)); + $error = FALSE; foreach ($po as $msg) { Log::info(sprintf('%s: - Mail from [%s] to [%s]',self::LOGKEY,$msg->fftn,$msg->tftn)); // @todo Quick check that the packet should be processed by us. // @todo validate that the packet's zone is in the domain. - // Dispatch job. - if ($queue) - MessageProcess::dispatch($msg); - else - MessageProcess::dispatchSync($msg); + try { + // Dispatch job. + if ($queue) + MessageProcess::dispatch($msg); + else + MessageProcess::dispatchSync($msg); + + } catch (Exception $e) { + Log::error(sprintf('%s:! Got error dispatching message [%s] (%d:%s-%s).',self::LOGKEY,$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage())); + $error = TRUE; + } } - if ($po->errors->count()) { + if ($po->errors->count() || $error) { Log::info(sprintf('%s: - Not deleting packet [%s], as it has validation errors',self::LOGKEY,$this->file)); // If we want to keep the packet, we could do that logic here