I have 2 environments, QA (1 webserver) and Prod (2 webservers behind a load balancer) that have been set up the same way using a database queue.
On QA everything works just fine.
On Production, I have some strange behaviour...Mailable works fine using the Queue but an email Notification doesn't work with the queue.
If I remove the queue from the notification, the email gets sent.
On QA, I can see both jobs being created in the jobs table. On Prod, only Mailable gets created in the jobs table.
Example with Activation Email:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class SendActivationEmail extends Notification implements ShouldQueue
{
use Queueable;
protected $token;
/**
* Create a new notification instance.
*
* SendActivationEmail constructor.
* @param $token
*/
public function __construct($token)
{
$this->token = $token;
$this->onQueue('social');
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Activation email')
->greeting('xxxxxx - Hello!')
->line('You need to activate your email before you can start using all of our services.')
->action('Activate Email', route('authenticated.activate', ['token' => $this->token]))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
My .env file:
QUEUE_DRIVER=database
The file config/queue.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd",
| "sqs", "iron", "redis"
|
*/
'default' => env('QUEUE_DRIVER', 'database'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
|
*/
'connections' => [
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
And my Mailable that works with queue:
Mail::to($user->email)
->queue(new Welcome($user));
Many thanks for your help
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire