#124: Made the queue settings configurable through the .env file

This commit is contained in:
Andy Heathershaw 2019-07-14 16:12:56 +01:00
parent 4905dd1caa
commit 461517dd55
2 changed files with 16 additions and 8 deletions

View File

@ -10,11 +10,9 @@ use Illuminate\Mail\Message;
class SendEmailsCommand extends Command class SendEmailsCommand extends Command
{ {
const MAX_EMAILS_PER_BATCH = 100; private $maxPerBatch;
private $numberOfAttempts;
const MAX_NUMBER_ATTEMPTS = 5; private $secondsBetweenPolls;
const SECONDS_TO_SLEEP = 30;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
@ -38,6 +36,10 @@ class SendEmailsCommand extends Command
public function __construct() public function __construct()
{ {
parent::__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([ $emailsToSend = EmailLog::where([
['sent_at', null], ['sent_at', null],
['number_attempts', '<', self::MAX_NUMBER_ATTEMPTS] ['number_attempts', '<', $this->numberOfAttempts]
])->limit(self::MAX_EMAILS_PER_BATCH)->get(); ])->limit($this->maxPerBatch)->get();
$this->output->writeln(sprintf( $this->output->writeln(sprintf(
'%d e-mail%s to send', '%d e-mail%s to send',
@ -82,7 +84,7 @@ class SendEmailsCommand extends Command
exit(); exit();
} }
sleep(self::SECONDS_TO_SLEEP); sleep($this->secondsBetweenPolls);
} }
} }

View File

@ -134,4 +134,10 @@ return [
resource_path('views/vendor/mail'), 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)
]
]; ];