各位使用队列遇到过吗? 默认监听可以工作 但是总抛异常?求指教 调试信息正文

我是打算用队列来异步发邮件的,邮件可以发,只是shell不停的抛出异常,略微不爽。

我视图自行追踪代码,但是无奈laravel的代码很复杂,暂时无果。
调试信息如下,求指教

commnd:

php artisan 
queue:listen

exception:

   [ErrorException]
   Undefined index: job

Stack trace:

\#0 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(125): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/mnt/hgfs/web/i...', 125, Array)
\#1 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Jobs/RedisJob.php(50): Illuminate\Queue\Jobs\Job->resolveAndFire(Array)
\#2 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(202): Illuminate\Queue\Jobs\RedisJob->fire()
\#3 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(153): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), '0', '0')
\#4 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(109): Illuminate\Queue\Worker->pop(NULL, 'default', '0', '3', '0')
\#5 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(71): Illuminate\Queue\Console\WorkCommand->runWorker(NULL, 'default', '0', '128', false)
\#6 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
\#7 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): call_user_func_array(Array, Array)
\#8 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Console/Command.php(149): Illuminate\Container\Container->call(Array)
\#9 /mnt/hgfs/web/icd/vendor/symfony/console/Command/Command.php(259): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#10 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Console/Command.php(135): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#11 /mnt/hgfs/web/icd/vendor/symfony/console/Application.php(878): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#12 /mnt/hgfs/web/icd/vendor/symfony/console/Application.php(195): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#13 /mnt/hgfs/web/icd/vendor/symfony/console/Application.php(126): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#14 /mnt/hgfs/web/icd/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(98): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#15 /mnt/hgfs/web/icd/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
\#16 {main}`
jasonchang
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 8
Summer

你是怎么调用的, Mail::queue ?

建议使用下面这种方法:

  1. dispatch
$this->dispatch(new SendReminderEmail($user));
  1. send
<?php

namespace App\Jobs;

use App\User;
use App\Jobs\Job;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendReminderEmail extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    protected $user;

    /**
     * Create a new job instance.
     *
     * @param  User  $user
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @param  Mailer  $mailer
     * @return void
     */
    public function handle(Mailer $mailer)
    {
        $mailer->send('emails.reminder', ['user' => $this->user], function ($m) {
            //
        });

        $this->user->reminders()->create(...);
    }
}
4年前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!