I have a series of drivers for sending emails, for example Gmail, Yahoo, etc. The structure of the database:
drivers_table:
id name host status user pass
1 Gmail google.com 1 user1 pass1
2 Yahoo yahoo.com 1 user2 pass2
messages_table:
id msg driver_id status
1 hi null 0
2 hi2 null 0
I want to balance these messages and send them through Laravel and cran Jobs in a balanced way between the drivers.
My attempt to do so:
$schedule->job(new SendMessageCron())->everyMinute();
class SendMessageCron extends Command
{
....
public function handle()
{
$dirvers = Driver::all();
$msgs = Messages::all();
foreach($dirvers as $driver) {
SendMessageJob::dispatch($driver, $msgs);
}
}
}
php artisan queue:work
class SendMessageJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $driver;
private $messages;
public function __construct( $driver, $messages)
{
$this->driver = $driver;
$this->messages = $messages;
}
public function handle()
{
// email send code
}
}
My questions are:
1- Is this structure correct?
2- Each submission made by SendMessageJob.php may take a long time and a new request will be sent to SendMessageJob.php again, but another driver is empty and can be sent and I do not want the request to be rejected, what should I do to do this?