8000 [Mailer] Add `retry_period` option for email transport by sdespont · Pull Request #54939 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Add retry_period option for email transport #54939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add retry_period option for email transport
  • Loading branch information
Sébastien Despont authored and fabpot committed Jan 4, 2025
commit c5703ae6e27bc8d30fefe91315a745d0b171f331
5 changes: 5 additions & 0 deletions src/Symfony/Component/Mailer/Tests/TransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static function fromStringProvider(): iterable
'roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)',
new RoundRobinTransport([$transportA, new FailoverTransport([$transportB, $transportA]), $transportB]),
];

yield 'round robin transport with retry period' => [
'roundrobin(dummy://a dummy://b)?retry_period=15',
new RoundRobinTransport([$transportA, $transportB], 15),
];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Component/Mailer/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public function fromStrings(#[\SensitiveParameter] array $dsns): Transports
public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface
{
[$transport, $offset] = $this->parseDsn($dsn);
if ($offset !== \strlen($dsn)) {
$dnsWithoutMainOptions = preg_replace('/[?&]retry_period=\d+/', '', $dsn);
if ($offset !== \strlen($dnsWithoutMainOptions)) {
throw new InvalidArgumentException('The mailer DSN has some garbage at the end.');
}

Expand All @@ -121,6 +122,10 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
'roundrobin' => RoundRobinTransport::class,
];

$parsedUrl = parse_url($dsn);
parse_str($parsedUrl['query'] ?? '', $query);
$retryPeriod = min((int) ($query['retry_period'] ?? 60), 60);

while (true) {
foreach ($keywords as $name => $class) {
$name .= '(';
Expand All @@ -145,7 +150,7 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
}
}

return [new $class($args), $offset];
return [new $class($args, $retryPeriod), $offset];
}
}

Expand Down
0