Update counts of sending queue when triggering post notification

When we trigger post notification sending we used to create post notification history record,
save all scheduled task subscribers but didn't update counts on queue.
Counts were eventually updated when sending started. This was causing some issues e.g. when sending
got stuck post notification item was showing 0/0 in sending status.
Pausing/resuming such a post notification caused that it was immediately set as sent.

This commit adds updating counts in queue immediately when sending starts.
[MAILPOET-3962]
This commit is contained in:
Rostislav Wolny
2021-11-19 15:42:55 +01:00
committed by Veljko V
parent bbb23e4f37
commit 6f5cde2fbf
2 changed files with 4 additions and 1 deletions

View File

@@ -104,7 +104,7 @@ class Scheduler {
return true; return true;
} }
public function processPostNotificationNewsletter($newsletter, $queue) { public function processPostNotificationNewsletter($newsletter, SendingTask $queue) {
$this->loggerFactory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo( $this->loggerFactory->getLogger(LoggerFactory::TOPIC_POST_NOTIFICATIONS)->addInfo(
'process post notification in scheduler', 'process post notification in scheduler',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->taskId] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->taskId]
@@ -137,6 +137,7 @@ class Scheduler {
// queue newsletter for delivery // queue newsletter for delivery
$queue->newsletterId = $notificationHistory->id; $queue->newsletterId = $notificationHistory->id;
$queue->updateCount();
$queue->status = null; $queue->status = null;
$queue->save(); $queue->save();
// update notification status // update notification status

View File

@@ -522,6 +522,8 @@ class SchedulerTest extends \MailPoetTest {
$updatedQueueSubscribers = $updatedQueue->getSubscribers(ScheduledTaskSubscriber::STATUS_UNPROCESSED); $updatedQueueSubscribers = $updatedQueue->getSubscribers(ScheduledTaskSubscriber::STATUS_UNPROCESSED);
expect($updatedQueueSubscribers)->equals([$subscriber->id]); expect($updatedQueueSubscribers)->equals([$subscriber->id]);
expect($updatedQueue->newsletterId)->equals($notificationHistory->id); expect($updatedQueue->newsletterId)->equals($notificationHistory->id);
expect($updatedQueue->countProcessed)->equals(0);
expect($updatedQueue->countToProcess)->equals(1);
// set notification history's status to sending // set notification history's status to sending
$updatedNotificationHistory = Newsletter::where('parent_id', $newsletter->id) $updatedNotificationHistory = Newsletter::where('parent_id', $newsletter->id)
->findOne(); ->findOne();