Remove reading batch size from constructor

[MAILPOET-3588]
This commit is contained in:
Jan Lysý
2021-04-30 15:26:25 +02:00
committed by Veljko V
parent 3126998212
commit aba99b84f2
2 changed files with 10 additions and 5 deletions

View File

@ -29,7 +29,6 @@ use MailPoetVendor\Carbon\Carbon;
class SendingQueue {
public $mailerTask;
public $newsletterTask;
public $batchSize;
const TASK_BATCH_SIZE = 5;
const EMAIL_WITH_INVALID_SEGMENT_OPTION = 'mailpoet_email_with_invalid_segment';
@ -85,7 +84,6 @@ class SendingQueue {
$this->segmentsRepository = $segmentsRepository;
$this->mailerMetaInfo = new MetaInfo;
$this->wp = $wp;
$this->batchSize = $this->throttlingHandler->getBatchSize();
$this->loggerFactory = $loggerFactory;
$this->newslettersRepository = $newslettersRepository;
$this->cronHelper = $cronHelper;
@ -140,7 +138,7 @@ class SendingQueue {
}
// get subscribers
$subscriberBatches = new BatchIterator($queue->taskId, $this->batchSize);
$subscriberBatches = new BatchIterator($queue->taskId, $this->getBatchSize());
foreach ($subscriberBatches as $subscribersToProcessIds) {
$this->loggerFactory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->addInfo(
'subscriber batch processing',
@ -210,6 +208,10 @@ class SendingQueue {
}
}
public function getBatchSize(): int {
return $this->throttlingHandler->getBatchSize();
}
public function processQueue($queue, $newsletter, $subscribers, $timer) {
// determine if processing is done in bulk or individually
$processingMethod = $this->mailerTask->getProcessingMethod();

View File

@ -155,11 +155,14 @@ class SendingQueueTest extends \MailPoetTest {
}
public function testItConstructs() {
expect($this->sendingQueueWorker->batchSize)->equals(SendingThrottlingHandler::BATCH_SIZE);
expect($this->sendingQueueWorker->mailerTask instanceof MailerTask);
expect($this->sendingQueueWorker->newsletterTask instanceof NewsletterTask);
}
public function testItReturnsCorrectBatchSize(): void {
expect($this->sendingQueueWorker->getBatchSize())->equals(SendingThrottlingHandler::BATCH_SIZE);
}
public function testItEnforcesExecutionLimitsBeforeQueueProcessing() {
$sendingQueueWorker = Stub::make($this->getSendingQueueWorker(
Stub::makeEmpty(NewslettersRepository::class)),
@ -861,7 +864,7 @@ class SendingQueueTest extends \MailPoetTest {
$wp = new WPFunctions;
$wp->addFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
$sendingQueueWorker = $this->getSendingQueueWorker(Stub::makeEmpty(NewslettersRepository::class));
expect($sendingQueueWorker->batchSize)->equals($customBatchSizeValue);
expect($sendingQueueWorker->getBatchSize())->equals($customBatchSizeValue);
$wp->removeFilter('mailpoet_cron_worker_sending_queue_batch_size', $filter);
}