Monday, April 10, 2017

The failed() method is not being called when an Job fails in Laravel

Currently im creating a job to be queued but for some reason the failed() method is not being triggered when the code executed in the handle() method of the job throws an exception. Is this some kind of bug in Laravel or am I doing something wrong? the Queue::failing() method in my AppServiceProvider IS being called

  <?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');


  }
}

In the above job. The failed() method is never being called. We use supervisor to keep the queue running

Thank



via Dennis Stolmeijer

Advertisement