我们希望使用laravel
个工作向客户发送发票。
我们有这个工作班。它期望构造函数中的支付模型。
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendInvoiceEmail extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
public $paypalModel;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($paypalModel)
{
$this->paypalModel = $paypalModel;
}
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$rechnung = new \App\Classes\Rechnung\Rechnung($this->paypalModel);
$rechnung->platzhalterErsetzen();
$rechnung->pdfErzeugen();
\App\Classes\Mail::SendPHPMail([
'email'=> $this->paypalModel->benutzer->email,
'name' => $this->paypalModel->benutzer->vorname . ' ' .$this->paypalModel->benutzer->nachname,
'type' => 'SendInvoice',
'invoicePath'=> $rechnung->pdfTargetPath
]);
$this->paypalModel->rechnungGesendet = true;
$this->paypalModel->save();
}
}
如果我们将queue_driver
中的env
设置为sync
,则效果非常好。现在,如果我们将queue_driver
更改为database
并在作业上启动侦听器,我们始终会遇到此异常:
[2017-03-15 13:20:13] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'app\Models\Payment\PayPal\PayPal' not found in d:\project\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php:76 Stack trace:
#0 d:\project\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(42): App\Jobs\SendInvoiceEmail->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#1 [internal function]: App\Jobs\SendInvoiceEmail->__wakeup()
#2 d:\project\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(38): unserialize('O:25:"App\\Jobs\\...')
#3 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(130): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#4 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Jobs\DatabaseJob.php(49): Illuminate\Queue\Jobs\Job->resolveAndFire(Array)
#5 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(213): Illuminate\Queue\Jobs\DatabaseJob->fire()
#6 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(156): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), '0', '0')
#7 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(125): Illuminate\Queue\Worker->pop(NULL, 'rechnung', '0', '3', '0')
#8 d:\project\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(78): Illuminate\Queue\Console\WorkCommand->runWorker(NULL, 'rechnung', '0', '128', false)
#9 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#10 d:\project\vendor\laravel\framework\src\Illuminate\Container\Container.php(507): call_user_func_array(Array, Array)
#11 d:\project\vendor\laravel\framework\src\Illuminate\Console\Command.php(169): Illuminate\Container\Container->call(Array)
#12 d:\project\vendor\symfony\console\Command\Command.php(267): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 d:\project\vendor\laravel\framework\src\Illuminate\Console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 d:\project\vendor\symfony\console\Application.php(846): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 d:\project\vendor\symfony\console\Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 d:\project\vendor\symfony\console\Application.php(122): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 d:\project\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 d:\project\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 {main}
为什么监听器不知道该类,以及在sync
模式下运行时,它是否按预期工作?有人有提示,原因是什么以及在哪里搜索错误原因?
提前谢谢!
更新
我已经在@ niraj-shah的课程中添加了app\Models\Payment\PayPal\PayPal
课程:
...
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use app\Models\Payment\PayPal\PayPal;
class SendInvoiceEmail extends Job implements ShouldQueue
{
...
这并没有解决问题。仍然出现相同的错误消息。即使我删除旧创建的作业并执行了queue:restart
来加载新代码。还有其他提示吗?
答案 0 :(得分:0)
您的代码找不到PayPal
类。请在代码顶部添加use
语句(在其他use
语句之后)`指向PayPal类的位置。 E.g。
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Payment\PayPal\PayPal;
....