具有错误的Laravel作业不会失败并且不会在望远镜中显示

问题描述 投票:0回答:1

我已经设置了这样的电子邮件作业:

dispatch(new NewUserEmail($newUser->email, $newUser->username));

我的工作文件如下:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use App\Mail\NewUser;
use Mail;

class NewUserEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $email;
    protected $username;
    public $tries = 5;

    /**
     * Create a new job instance.
     */
    public function __construct($email, $username)
    {
        $this->email = $email;
        $this->username = $username;
    }

    /**
     * Execute the job.
     */
    public function handle()
    {
        try {
            Mail::to($this->email)->send(new NewUsedfr($this->username));
        } catch (\Exception $e) {
            Log::error('NewUserEmailJob failed NewUser');
            Log::error('NewUserEmailJob log: '.$e);
            throw new \Exception($e);
        }
    }
}

但是,我故意拼错了应为NewUsedfr的邮件文件NewUser为了尝试tigger一个例外。

但是当我运行作业时,我可以看到作业在Horizo​​n中完成而没有被标记为失败。在望远镜中,我无法在日志选项卡中看到任何异常或错误。

所以我手动查看了我的storage / logs文件夹,看到了这一行:

Class 'App\Jobs\NewUsedfr' not found {"exception":"[object]

所以为什么我的工作不会在地平线上失败,为什么望远镜中不会显示上述错误?望远镜看起来没有显示来自storage / logs文件夹的错误似乎有点奇怪]

我已经设置了这样一个电子邮件作业:dispatch(new NewUserEmail($ newUser-> email,$ newUser-> username));我的工作文件看起来像这样:

php laravel queue telescope horizon
1个回答
0
投票

代替抛出新的异常,而是抛出原始的异常:

throw $e; 
© www.soinside.com 2019 - 2024. All rights reserved.