8000 [Mailer] Make RoundRobinTransport retryPeriod configurable · Issue #52551 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Make RoundRobinTransport retryPeriod configurable #52551

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

Closed
ghost opened this issue Nov 11, 2023 · 4 comments
Closed

[Mailer] Make RoundRobinTransport retryPeriod configurable #52551

ghost opened this issue Nov 11, 2023 · 4 comments
Labels

Comments

@ghost
Copy link
ghost commented Nov 11, 2023

Description

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.

Example

No response

@alamirault
Copy link
Contributor

If we want to support it in DSN, we should probably edit

private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0): array
{
static $keywords = [
'failover' => FailoverTransport::class,
'roundrobin' => RoundRobinTransport::class,
];
while (true) {
foreach ($keywords as $name => $class) {
$name .= '(';
if ($name === substr($dsn, $offset, \strlen($name))) {
$offset += \strlen($name) - 1;
preg_match('{\(([^()]|(?R))*\)}A', $dsn, $matches, 0, $offset);
if (!isset($matches[0])) {
continue;
}
++$offset;
$args = [];
while (true) {
[$arg, $offset] = $this->parseDsn($dsn, $offset);
$args[] = $arg;
if (\strlen($dsn) === $offset) {
break;
}
++$offset;
if (')' === $dsn[$offset - 1]) {
break;
}
}
return [new $class($args), $offset];
}
}
if (preg_match('{(\w+)\(}A', $dsn, $matches, 0, $offset)) {
throw new InvalidArgumentException(sprintf('The "%s" keyword is not valid (valid ones are "%s"), ', $matches[1], implode('", "', array_keys($keywords))));
}
if ($pos = strcspn($dsn, ' )', $offset)) {
return [$this->fromDsnObject(Dsn::fromString(substr($dsn, $offset, $pos))), $offset + $pos];
}
return [$this->fromDsnObject(Dsn::fromString(substr($dsn, $offset))), \strlen($dsn)];
}
}

Is there any RFC/good practice for good syntax ?

@ghost
Copy link
Author
ghost commented Jan 16, 2024

@alamirault Yes, this method would have to be updated. About the good practice, I think that this should be done in a standard way, i.e. option are added as after the question mark (?), so it would be MAILER_DSN="roundrobin(postmark+api://ID@default sendgrid+smtp://KEY@default)?retry_period=15"

@gaelreyrol
Copy link

This issue is a duplicate of #50981.

@xabbuh
Copy link
Member
xabbuh commented Jan 19, 2024

closing in favour of #50981 then< A8C2 /p>

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2024
fabpot added a commit that referenced this issue Jan 4, 2025
… (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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
0