I set all the thing related to queue jobs in laravel and its working fine. But some time when I try to send email multiple times immediately then sometimes jobs table in the database is empty that means supervisor processed jobs but I don't get an email. I don't know what's going on.
I tried to research on it but no one has a suggestion for it.
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 0,
],
Controller
<?php
namespace App\Jobs;
date_default_timezone_set('utc');
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Mail;
use Log;
class SendEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $emailArray;
public function __construct($emailArray)
{
$this->emailArray = $emailArray;
}
public function handle()
{
try {
$emailArray = $this->emailArray;
switch ($emailArray['template_name']) {
case 'email1':
$email = $emailArray['email'];
Mail::send('emails.' . $emailArray['template_name'], $emailArray, function ($message) use ($email) {
$message->from(env('FromMail', 'myemail@gmail.com'), 'My Email');
$message->to($email)->subject('My Email| Forgot Password');
});
break;
}
return;
} catch (\Exception $e){Log::info($e->getMessage());}
}
}
Push job
try {
$userMailArray = [
'template_name' => 'email1',
'email' => $email,
'temp_password' => $temporaryPwd,
];
dispatch(new SendEmail($userMailArray));
} catch (\Exception $e) {
Session::flash('invalidMail', 'Something went wrong. Please try again.');
return back();
}```
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire