laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.21k stars 10.9k forks source link

Implements ShouldQueue not sending Notifications #20628

Closed Pegasus260985 closed 7 years ago

Pegasus260985 commented 7 years ago

Description:

Hi,

I'm implementing the Twilio notification channel to send sms notifications to my application users. Here is the problem:

The notification works perfect without the implements ShouldQueue

class orderRecieved extends Notification

As soon as I add it to the notification class it stop sending the SMS.

I've configured the queue.php to the database driver:

 'default' => env('QUEUE_DRIVER', 'database'),

 'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default',
            'retry_after' => 90,
        ],

Steps To Reproduce:

I've created the jobs and failed_jobs table. I can see the job when I delay the notification but it seems like it doesn't trigger it.

Here is the notification code orderReceived:

<?php

namespace App\Notifications;

use App\Models\Patient;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use NotificationChannels\Twilio\TwilioChannel;
use NotificationChannels\Twilio\TwilioSmsMessage;

class orderRecieved extends Notification implements ShouldQueue {

    use Queueable;
    /**
     * @var Patient
     */
    private $user;

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

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [TwilioChannel::class, 'mail'];
    }

    /**
     * @param $notifiable
     * @return mixed
     */
    public function toTwilio($notifiable)
    {
        return (new TwilioSmsMessage())
            ->content("Hi,\nVi har mottatt prøven(e) du har sendt til oss. Se vår nettside, www.lab1.no, for forventet svartid.\nMvh\nLab1 AS");
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line('The introduction to the notification.')
            ->action('Notification Action', 'https://laravel.com')
            ->line('Thank you for using our application!');
    }
}

Sending the notification:

$user = Patient::find($this->crud->entry->patient_id);
$when = Carbon::now()->addMinutes(1);
Notification::send($user, (new orderRecieved($user))->delay($when));

The mail Notification works perfect!

Any idea? Thank you for the help!!!

themsaid commented 7 years ago

Can't replicate your issue.

Pegasus260985 commented 7 years ago

Does it work for you?

themsaid commented 7 years ago

Yes, queued sms notifications are sent, have a test Horizon app that sends queued notifications and it's working.

Pegasus260985 commented 7 years ago

Are you using same TwilioChannel?

themsaid commented 7 years ago

But we use Nexmo channel, looks to me an issue with NotificationChannels\Twilio\TwilioChannel, please report your issue there since it's not a built-in channel.

imrealashu commented 5 years ago

I came across the same issue today and adding use SerializesModels fixed the issue for me.