浏览代码

添付ファイル存在しない場合に、メールジョブを終了させるように終了

develop
sosuke.iwabuchi 2 年前
父节点
当前提交
a514bfe98d
共有 3 个文件被更改,包括 40 次插入1 次删除
  1. +11
    -0
      app/Email/BaseEmailer.php
  2. +21
    -0
      app/Exceptions/TempFileNotExistsException.php
  3. +8
    -1
      app/Jobs/Email/SimpleEmail.php

+ 11
- 0
app/Email/BaseEmailer.php 查看文件

@@ -3,6 +3,7 @@
namespace App\Email;

use App\Exceptions\AppCommonException;
use App\Exceptions\TempFileNotExistsException;
use App\Models\Email;
use App\Models\EmailAttachment;
use App\Models\User;
@@ -82,7 +83,17 @@ abstract class BaseEmailer extends Mailable
if ($this->__attachments !== null) {
$count = $this->__attachments->count();
foreach ($this->__attachments as $attachment) {



$filepath = $attachment->filepath;


if (!file_exists($filepath)) {
$e = new TempFileNotExistsException();
throw $e->setFilepath($filepath);
}

$as = $attachment->send_filename;
$mime = $attachment->mime;
$this->attach($filepath, [


+ 21
- 0
app/Exceptions/TempFileNotExistsException.php 查看文件

@@ -0,0 +1,21 @@
<?php

namespace App\Exceptions;

use Exception;

class TempFileNotExistsException extends Exception
{
private $filepath = "";

public function setFilepath(string $filepath): static
{
$this->filepath = $filepath;
return $this;
}

public function getFilepath(): string
{
return $this->filepath;
}
}

+ 8
- 1
app/Jobs/Email/SimpleEmail.php 查看文件

@@ -4,8 +4,10 @@ namespace App\Jobs\Email;

use App\Codes\QueueName;
use App\Email\Sender;
use App\Exceptions\TempFileNotExistsException;
use App\Jobs\BaseJob;
use App\Models\Email;
use Illuminate\Support\Facades\Log;

class SimpleEmail extends BaseJob
{
@@ -29,6 +31,11 @@ class SimpleEmail extends BaseJob
*/
public function handle()
{
Sender::send($this->emailId);
try {
Sender::send($this->emailId);
} catch (TempFileNotExistsException $e) {
// 一時ファイルが存在しないため、処理終了
Log::warning(sprintf("ファイル存在しないため、メール送信処理スキップ :%s", $e->getFilepath()));
}
}
}

正在加载...
取消
保存