-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
FallbackMailer: shuffle mailers with given probability #35
base: master
Are you sure you want to change the base?
Conversation
@janedbal Can you elaborate? |
@JanTvrdik I don't like the intention. If you want to periodically test other mailers, include it in your CI or cron task. IMHO fallback mailer should be used in "emergency" cases, then you can for example track usage of the fallback mailer to measure reliability of your primary mailer. |
@janedbal Production SMTP servers are rarely tested on CI (because CI does not have access to production credentials). Also being able to send mail from CI does not mean you will be able to send mail from production (different firewall configuration…). Reliability can be tracked via |
Well, adding such functionality into a constructor isn't good. It also violates SRP. Introducing a "ShuffleMailer" may be the right way. |
Feel a lot like overengineering. This is three lines of code. Creating new class would just make this a lot harder to use. BTW: FallbackMailer intentionally already violates SRP (the „correct“ approach would be to split it to RetryingMailer and FallbackMailer). |
💯 |
Agreed. Maybe the question is if a such unique functionality should be included in the framework.
This argument is based on the actual implementation, but the general intention is in your case totally different - the current Fallback mailer tries to send the mail in any case, tries to solve some failures and outages. Your extension actually doesn't increase such possibility of successfull send at all, but it introduces possibility to test the infrastructure. That's another usecase, therefore the logic should be IMO separated. |
This clearly doesn't sound like something that should be done in production. If your mailers are unreliable, you should test them in different manner, i.e. by your monitoring, not by randomly using them in production (or rather not use them in production at all)... FallbackMailer should probably be renamed to FallbackRetryingAndWaitingAndTestingByShufflingMailer. Seriously, shuffling of the mailers has absolutely no relation to fallback mailing. Also it's just a rare use case imho (which you can easily implement in user-land). |
I disagree, imho production is the only place this can be accurately done from. Yes, you can use monitoring to test whether the mail servers are running, but that does not mean that the application will be able to actually send mails.
Maybe |
Because it instantly modifies the input argument and because it is tricky (or hard to explain, reuse, whatever), I think it can be better solved in the config: mail.mailer: Nette\Mail\FailbackMailer(MyTools::suffleMailers([@onemailer, @secondmailer])) function MyTools::suffleMailers(array $mailers, $shuffleProbability = 0.01)
{
if ($shuffleProbability > 0.0 && mt_rand() / mt_getrandmax() < $shuffleProbability) {
shuffle($mailers);
}
return $mailers;
} |
We can move the actual shuffle to |
54f29d0
to
c22f629
Compare
e124e7f
to
e99a03c
Compare
78a8e13
to
65b6e63
Compare
4b89780
to
d0183d1
Compare
202657a
to
ec15558
Compare
543191d
to
d0ad5f9
Compare
c140ba8
to
12b1cf3
Compare
6569722
to
deb839e
Compare
1683d77
to
90bf62a
Compare
Intended to periodically test the other mailers.
I'm not sure whether default
$shuffleProbability
should be0.0
or sth like0.001
(would be a minor BC break).