【发布时间】:2019-11-20 15:53:04
【问题描述】:
我已经设置了这样的电子邮件工作:
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
为了尝试触发异常。
但是当我运行作业时,我可以看到作业在 Horizon 中完成,而没有被标记为失败。 在望远镜中看,我在日志选项卡中看不到任何异常或错误..
所以我手动查看了我的 storage/logs 文件夹,我看到了这一行:
Class 'App\Jobs\NewUsedfr' not found {"exception":"[object]
那么为什么我的工作没有在地平线上失败,为什么上述错误没有在望远镜中显示?望远镜没有显示存储/日志文件夹中的错误似乎有点奇怪
【问题讨论】:
-
你可以尝试重新抛出原始异常而不是抛出一个新的异常吗?抛出 $e;
-
我猜 Horizon 是在生产服务器上?
-
@AlexandreDanault Throw $e 导致工作失败,谢谢!
-
@user2722667 很高兴它有效,现在作为答案发布,以便您接受。
标签: php laravel queue telescope horizon