【问题标题】:The failed() method is not being called when an Job fails in Laravel 5.4当 Laravel 5.4 中的作业失败时,不调用 failed() 方法
【发布时间】:2017-09-05 09:57:51
【问题描述】:

目前我正在创建一个要排队的作业,但由于某种原因,当作业的handle() 方法中执行的代码抛出异常时,failed() 方法没有被触发。这是 Laravel 中的某种错误还是我做错了什么?正在调用我的 AppServiceProvider 中的 Queue::failing() 方法

  <?php
    namespace App\Jobs;

    use App\Models\Email;
    use Carbon\Carbon;
    use Illuminate\Bus\Queueable;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Queue\InteractsWithQueue;
    use Illuminate\Contracts\Queue\ShouldQueue;

    class MyCommand implements ShouldQueue
    {
        use InteractsWithQueue, Queueable, SerializesModels;

        protected $lead;

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

        /**
         * Execute the job.
         */
        public function handle()
        {
            throw new \Exception("error!");
        }

        /**
         * The job failed to process.
         *
         * @param \Exception $exception
         */
        public function failed(\Exception $exception)
        {
            \Log::critical('wooot');
        }
}

在上述工作中。 failed() 方法永远不会被调用。我们使用supervisor来保持队列运行

谢谢

【问题讨论】:

  • 哪个 laravel 版本?
  • laravel版本是5.4
  • 您如何调度作业以及如何运行它以及使用哪个驱动程序?另外,您可能想在src/Illuminate/Queue/FailingJob.php 中放置一些日志并在那里调试..

标签: php laravel


【解决方案1】:

看起来好像调用了 failed() 方法,但因为 $lead 属性不是公共的。当我想检索属性的内容时遇到异常。

【讨论】:

    猜你喜欢
    • 2019-01-19
    • 2018-12-30
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2011-06-01
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多