dimanche 27 septembre 2020

Laravel Email in Job Queue not working except sync

I am using Laravel 5.8, I configured an email containing the invoice sent to user after they place an order. Email is delivered when set QUEUE_DRIVER=sync but when I set it to redis/database and I run the php artisan queue:work redis --tries=5 it shows the queue is processed

Processing: Modules\Checkout\Mail\Invoice
Processed: Modules\Checkout\Mail\Invoice

succesfully and no entry in the failed_jobs either.

CODE: Modules\Checkout\Jobs\SendInvoiceEmail.php

    class SendInvoiceEmail implements ShouldQueue
    {
      use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

      public $order;
      public function __construct(Order $order)
      {
        $this->order = $order;
      }

      public function handle()
      {
        Mail::to($this->order->customer_email)
              ->send(new Invoice($this->order));
      }
    }

And this is the Modules\Checkout\Mail\Invoice.php

class Invoice extends Mailable
{
    use Queueable, SerializesModels;

    public $order;

    public function __construct($order)
    {
        $this->order = $order;
    }

    public function build()
    {
        return $this->subject('New order: ', ['id' => $this->order->id]))
            ->view("emails.invoice");
    }

}

Then I am dispatching it in the Controller after Order created
SendInvoiceEmail::dispatch($order);

Can anyone point out if I've missed anything and what I am doing wrong?

I've done the php artisan config:cache and clear:cache restarted the server.

This works just as expected if I set QUEUE_DRIVER=sync in .env instead of QUEUE_DRIVER=redis or database



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/36nWTfl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire