From a1abf5016f6830e54809c2a88252f61400180495 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 10 Oct 2024 23:46:25 +0900 Subject: [PATCH] Integrate Mail and SMS with Queue --- common/framework/Mail.php | 18 ++++++++++++++++++ common/framework/SMS.php | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/common/framework/Mail.php b/common/framework/Mail.php index 7502c6df9..bcf9b62a3 100644 --- a/common/framework/Mail.php +++ b/common/framework/Mail.php @@ -560,6 +560,13 @@ class Mail */ public function send(): bool { + // If queue is enabled, send asynchronously. + if (config('queue.enabled') && !defined('RXQUEUE_CRON')) + { + Queue::addTask(self::class . '::' . 'sendAsync', $this); + return true; + } + // Get caller information. $backtrace = debug_backtrace(0); if(count($backtrace) && isset($backtrace[0]['file'])) @@ -600,6 +607,17 @@ class Mail return $this->sent; } + /** + * Send an email asynchronously (for Queue integration). + * + * @param self $mail + * @return void + */ + public static function sendAsync(self $mail): void + { + $mail->send(); + } + /** * Check if the message was sent. * diff --git a/common/framework/SMS.php b/common/framework/SMS.php index 0d347bc83..4bb65fd60 100644 --- a/common/framework/SMS.php +++ b/common/framework/SMS.php @@ -511,6 +511,13 @@ class SMS */ public function send(): bool { + // If queue is enabled, send asynchronously. + if (config('queue.enabled') && !defined('RXQUEUE_CRON')) + { + Queue::addTask(self::class . '::' . 'sendAsync', $this); + return true; + } + // Get caller information. $backtrace = debug_backtrace(0); if(count($backtrace) && isset($backtrace[0]['file'])) @@ -566,6 +573,17 @@ class SMS return $this->sent; } + /** + * Send an SMS asynchronously (for Queue integration). + * + * @param self $sms + * @return void + */ + public static function sendAsync(self $sms): void + { + $sms->send(); + } + /** * Check if the message was sent. *