From 461517dd55f7a284657c61761bf44e84f3e9b4dd Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Sun, 14 Jul 2019 16:12:56 +0100 Subject: [PATCH] #124: Made the queue settings configurable through the .env file --- app/Console/Commands/SendEmailsCommand.php | 18 ++++++++++-------- config/mail.php | 6 ++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/SendEmailsCommand.php b/app/Console/Commands/SendEmailsCommand.php index a26ea22..71e36c1 100644 --- a/app/Console/Commands/SendEmailsCommand.php +++ b/app/Console/Commands/SendEmailsCommand.php @@ -10,11 +10,9 @@ use Illuminate\Mail\Message; class SendEmailsCommand extends Command { - const MAX_EMAILS_PER_BATCH = 100; - - const MAX_NUMBER_ATTEMPTS = 5; - - const SECONDS_TO_SLEEP = 30; + private $maxPerBatch; + private $numberOfAttempts; + private $secondsBetweenPolls; /** * The name and signature of the console command. @@ -38,6 +36,10 @@ class SendEmailsCommand extends Command public function __construct() { parent::__construct(); + + $this->maxPerBatch = config('mail.queue.emails_per_batch'); + $this->numberOfAttempts = config('mail.queue.max_attempts'); + $this->secondsBetweenPolls = config('mail.queue.seconds_between_polls'); } /** @@ -62,8 +64,8 @@ class SendEmailsCommand extends Command { $emailsToSend = EmailLog::where([ ['sent_at', null], - ['number_attempts', '<', self::MAX_NUMBER_ATTEMPTS] - ])->limit(self::MAX_EMAILS_PER_BATCH)->get(); + ['number_attempts', '<', $this->numberOfAttempts] + ])->limit($this->maxPerBatch)->get(); $this->output->writeln(sprintf( '%d e-mail%s to send', @@ -82,7 +84,7 @@ class SendEmailsCommand extends Command exit(); } - sleep(self::SECONDS_TO_SLEEP); + sleep($this->secondsBetweenPolls); } } diff --git a/config/mail.php b/config/mail.php index a4496b0..62bc5c4 100644 --- a/config/mail.php +++ b/config/mail.php @@ -134,4 +134,10 @@ return [ resource_path('views/vendor/mail'), ], ], + + 'queue' => [ + 'emails_per_batch' => env('QUEUE_EMAILS_PER_BATCH', 100), + 'seconds_between_polls' => env('QUEUE_SECONDS_PER_POLL', 30), + 'max_attempts' => env('QUEUE_MAX_ATTEMPTS', 5) + ] ];