You are here

protected function SendMailQueueWorker::processRetryLimit in Queue Mail 8

Retry limit handler.

Counts number of attempts and removes mails from queue after reaching threshold.

Parameters

array $original_message: Original message.

1 call to SendMailQueueWorker::processRetryLimit()
SendMailQueueWorker::processItem in src/Plugin/QueueWorker/SendMailQueueWorker.php
Works on a single queue item.

File

src/Plugin/QueueWorker/SendMailQueueWorker.php, line 273

Class

SendMailQueueWorker
Sends emails form queue.

Namespace

Drupal\queue_mail\Plugin\QueueWorker

Code

protected function processRetryLimit(array $original_message) {
  $original_message['last_attempt'] = time();
  if (!isset($original_message['fail_count'])) {
    $original_message['fail_count'] = 0;
  }
  $original_message['fail_count']++;
  $threshold = $this->config
    ->get('threshold');

  // Add back to the queue with an updated fail count.
  if ($original_message['fail_count'] < $threshold) {
    $this->queue
      ->createItem($original_message);
  }
  else {
    $this->logger
      ->error('Attempt sending email (from %from to %to with reply-to %reply) exceeded retry threshold and was deleted.', [
      '%from' => $original_message['from'],
      '%to' => $original_message['to'],
      '%reply' => $original_message['reply-to'] ? $original_message['reply-to'] : $this
        ->t('not set'),
    ]);
  }
}