我已经创建了作业文件,并且正在通过使用mailable的控制器分派邮件,它将在作业表中创建条目,但是在几秒钟之后,它将把记录转移到fail_jobs表中,并提供未找到的错误模型< / p>
控制器调度方法
if (!empty($emails) && isset($result->email)) {
dispatch(new SendNotificationEmailJob($emails, $result, 'WarehouseAddUpdate', array($subject, $request['number'], 'add')));
}
SendNotificationEmailJob类
<?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\Mail;
class SendNotificationEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $emails;
protected $result;
protected $mailClass;
protected $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($emails, $result, $mailClass, $data)
{
$this->emails = $emails;
$this->result = $result;
$this->mailClass = 'App\Mail\\'.$mailClass;
$this->data = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if ($this->result == null) {
if (!empty($this->emails)) {
$to = $this->emails[0];
unset($this->emails[0]);
}
}else{
if($this->result != null && isset($this->result->email)){
$to = $this->result->email;
if (($key = array_search($this->result->email, $this->emails)) !== false) {
unset($this->emails[$key]);
}
}
}
if (!empty($this->emails) && isset($result->email)) {
$email = new $this->mailClass($this->data);
Mail::to($to)->cc($this->emails)->send($email);
}
if (empty($emails) && isset($result->email)) {
$email = new $this->mailClass($this->data);
Mail::to($to)->send($email);
}
}
}
可邮寄类
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class WarehouseAddUpdate extends Mailable
{
use Queueable, SerializesModels;
/**
* The data object instance.
*
* @var data
*/
public $subject;
public $warehouse;
public $type;
public $oldstatus;
public $newstatus;
public $receiver;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->subject = $data[0];
$this->warehouse = $data[1];
$this->type = $data[2];
$this->oldstatus = $data[3] ?? null;
$this->newstatus = $data[4] ?? null;
$this->receiver = 'Manager';
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('mails.warehouseaddupdate')->subject($this->subject);
}
}
我在数据库failed_jobs表中发现的错误
Illuminate \ Database \ Eloquent \ ModelNotFoundException:无查询结果 对于模型[App \ Model \ V1 \ User]。在 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:416 堆栈跟踪:
0 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(54):
Illuminate \ Database \ Eloquent \ Builder-> firstOrFail()
1 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(41):
App \ Jobs \ SendNotificationEmailJob-> getRestoredPropertyValue(Object(Illuminate \ Contracts \ Database \ ModelIdentifier))
2 [内部功能]:App \ Jobs \ SendNotificationEmailJob-> __ wakeup()
3 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42):
unserialize('O:33:“ App \ Jobs \ ...')
4 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(76):
Illuminate \ Queue \ CallQueuedHandler->调用(Object(Illuminate \ Queue \ Jobs \ DatabaseJob), 数组)
5 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(320):
Illuminate \ Queue \ Jobs \ Job-> fire()
6 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(270):
Illuminate \ Queue \ Worker-> process('database', 对象(Illuminate \ Queue \ Jobs \ DatabaseJob), 对象(Illuminate \ Queue \ WorkerOptions))
7 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(114):
Illuminate \ Queue \ Worker-> runJob(Object(Illuminate \ Queue \ Jobs \ DatabaseJob), '数据库',对象(Illuminate \ Queue \ WorkerOptions))
8 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101):
Illuminate \ Queue \ Worker-> daemon('database','default', 对象(Illuminate \ Queue \ WorkerOptions))
9 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85):
Illuminate \ Queue \ Console \ WorkCommand-> runWorker('database','default')
10 [内部功能]:Illuminate \ Queue \ Console \ WorkCommand-> handle()
11 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29):
call_user_func_array(Array,Array)
12 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87):
Illuminate \ Container \ BoundMethod :: Illuminate \ Container {closure}()
13 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31):
Illuminate \ Container \ BoundMethod :: callBoundMethod(Object(Illuminate \ Foundation \ Application), 数组,对象(关闭))
14 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Container/Container.php(549):
Illuminate \ Container \ BoundMethod :: call(Object(Illuminate \ Foundation \ Application), Array,Array,NULL)
15 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Console/Command.php(183):
Illuminate \ Container \ Container-> call(Array)
16 /var/www/html/smartcgd/vendor/symfony/console/Command/Command.php(252):
Illuminate \ Console \ Command-> execute(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Illuminate \ Console \ OutputStyle)
17 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Console/Command.php(170):
Symfony \ Component \ Console \ Command \ Command-> run(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Illuminate \ Console \ OutputStyle)
18 /var/www/html/smartcgd/vendor/symfony/console/Application.php(946):
Illuminate \ Console \ Command-> run(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
19 /var/www/html/smartcgd/vendor/symfony/console/Application.php(248):
Symfony \ Component \ Console \ Application-> doRunCommand(Object(Illuminate \ Queue \ Console \ WorkCommand), 对象(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
20 /var/www/html/smartcgd/vendor/symfony/console/Application.php(148):
Symfony \ Component \ Console \ Application-> doRun(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
21 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Console/Application.php(88):
Symfony \ Component \ Console \ Application-> run(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
22 /var/www/html/smartcgd/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121):
Illuminate \ Console \ Application-> run(Object(Symfony \ Component \ Console \ Input \ ArgvInput), 对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
23 / var / www / html / smartcgd / artisan(37):Illuminate \ Foundation \ Console \ Kernel-> handle(Object(Symfony \ Component \ Console \ Input \ ArgvInput),
对象(Symfony \ Component \ Console \ Output \ ConsoleOutput))
24 {main}