I have email sending service to send broadcast to all customers. Customer number can be above 10k and I am using laravel queue for this.
I have made chunks with size 100 and looped over chunks to send email using following mail class.
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
/**
* Class BroadcastEmail
* @package App\Mail
*/
class BroadcastEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* @var
*/
private $title;
/**
* @var
*/
private $body;
/**
* @var
*/
private $url;
/**
* @var
*/
private $image;
/**
* Create a new body instance.
*
* @param $title
* @param $body
* @param $url
* @param $image
* @return void
*/
public function __construct($title, $body, $url, $image)
{
$this->title = $title;
$this->body = $body;
$this->url = $url;
$this->image = $image;
}
/**
* Build the body.
*
* @return $this
*/
public function build()
{
return $this
->subject($this->title)
->view('emails.broadcast')
->with(
[
'body' => $this->body,
'url' => $this->url,
'image' => $this->image
]
);
}
}
In the local server, I just run queue:work
command in console and everything works perfectly untill i terminate the queue worker.
However I don't have console access to my production server. I have shared hosting cpanel.
What should I do to execute all the jobs in the queue in production ?
Should I make a cron job to run queue:work command and execute it periodically ?
or
I have to execute queue:work once programmatically in server ?
Which of these will work or is there any better correct way to execute queue worker in cpanel ?
Any kind of suggestions are appreciated.
P.S. I have already visited this question before asking since I don't get any idea from the answer.