Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41bee39

Browse filesBrowse files
committed
feature #54939 [Mailer] Add retry_period option for email transport (Sébastien Despont, fabpot)
This PR was merged into the 7.3 branch. Discussion ---------- [Mailer] Add `retry_period` option for email transport | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #50981 #52551 | License | MIT RoundRobinTransport constructor has retryPeriod set to 60 seconds. This cannot be configured right now. Let's say all the transports fail (e.g. email address with domain that does not exist). Problems: 1. When sending more than one email synchronously we can't send emails following the one that failed. We have to sleep(x) where x >= 60sec. (of course we have to handle the TransportException thrown by invalid email but this is another topic) 2. When using Messenger and async emails we don't have to worry about handling TransportException because invalid message will be sent back to the queue however the worker cannot consume another messages for the next 60 seconds. Also logs will be flooded with exceptions because in this 60s window a lot of messages could be tried. This PR permits to specify a retry period using a new DNS option `retry_period` like `MAILER_DSN="roundrobin(postmark+api://ID@default sendgrid+smtp://KEY@default)?retry_period=15"` Commits ------- 9716a89 Simplify code c5703ae Add retry_period option for email transport
2 parents 04ee771 + 9716a89 commit 41bee39
Copy full SHA for 41bee39

File tree

2 files changed

+10
-0
lines changed
Filter options

2 files changed

+10
-0
lines changed

‎src/Symfony/Component/Mailer/Tests/TransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/TransportTest.php
+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public static function fromStringProvider(): iterable
5858
'roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)',
5959
new RoundRobinTransport([$transportA, new FailoverTransport([$transportB, $transportA]), $transportB]),
6060
];
61+
62+
yield 'round robin transport with retry period' => [
63+
'roundrobin(dummy://a dummy://b)?retry_period=15',
64+
new RoundRobinTransport([$transportA, $transportB], 15),
65+
];
6166
}
6267

6368
/**

‎src/Symfony/Component/Mailer/Transport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport.php
+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
145145
}
146146
}
147147

148+
parse_str(substr($dsn, $offset + 1), $query);
149+
if ($period = $query['retry_period'] ?? 0) {
150+
return [new $class($args, (int) $period), $offset + \strlen('retry_period='.$period) + 1];
151+
}
152+
148153
return [new $class($args), $offset];
149154
}
150155
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.