Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
bug #749 Retry sending messages in the memory spool before aborting i…
Browse files Browse the repository at this point in the history
…n case of transport failure (Seldaek)

This PR was merged into the 5.x branch.

Discussion
----------

Retry sending messages in the memory spool before aborting in case of transport failure

Commits
-------

4afba32 Retry sending messages in the memory spool before aborting in case of transport failure
  • Loading branch information
fabpot committed Apr 30, 2016
2 parents e4fae9e + 4afba32 commit 742847c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/classes/Swift/MemorySpool.php
Expand Up @@ -16,6 +16,7 @@
class Swift_MemorySpool implements Swift_Spool
{
protected $messages = array();
private $flushRetries = 3;

/**
* Tests if this Transport mechanism has started.
Expand All @@ -41,6 +42,14 @@ public function stop()
{
}

/**
* @param int $retries
*/
public function setFlushRetries($retries)
{
$this->flushRetries = $retries;
}

/**
* Stores a message in the queue.
*
Expand Down Expand Up @@ -75,8 +84,25 @@ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null
}

$count = 0;
while ($message = array_pop($this->messages)) {
$count += $transport->send($message, $failedRecipients);
$retries = $this->flushRetries;
while ($retries--) {
try {
while ($message = array_pop($this->messages)) {
$count += $transport->send($message, $failedRecipients);
}
} catch (Swift_TransportException $exception) {
if ($retries) {
// re-queue the message at the end of the queue to give a chance
// to the other messages to be sent, in case the failure was due to
// this message and not just the transport failing
array_unshift($this->messages, $message);

// wait half a second before we try again
usleep(500000);
} else {
throw $exception;
}
}
}

return $count;
Expand Down

0 comments on commit 742847c

Please sign in to comment.