Integrate Mail and SMS with Queue

This commit is contained in:
Kijin Sung 2024-10-10 23:46:25 +09:00
parent f6a458f648
commit a1abf5016f
2 changed files with 36 additions and 0 deletions

View file

@ -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.
*

View file

@ -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.
*