From bf970f32f571164b8081f09f602a3473e079194e Mon Sep 17 00:00:00 2001 From: hackerman <3372410+aeneasr@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:21:01 +0200 Subject: [PATCH] fix(courier): add ability to specify backoff (#2349) --- courier/courier.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/courier/courier.go b/courier/courier.go index 2eb1f647d00f..a4e8d7d9465c 100644 --- a/courier/courier.go +++ b/courier/courier.go @@ -32,6 +32,7 @@ type ( DispatchMessage(ctx context.Context, msg Message) error SetGetEmailTemplateType(f func(t EmailTemplate) (TemplateType, error)) SetNewEmailTemplateFromMessage(f func(d template.Dependencies, msg Message) (EmailTemplate, error)) + UseBackoff(b backoff.BackOff) } Provider interface { @@ -47,6 +48,7 @@ type ( smtpClient *smtpClient deps Dependencies failOnError bool + backoff backoff.BackOff } ) @@ -55,6 +57,7 @@ func NewCourier(ctx context.Context, deps Dependencies) Courier { smsClient: newSMS(ctx, deps), smtpClient: newSMTP(ctx, deps), deps: deps, + backoff: backoff.NewExponentialBackOff(), } } @@ -79,11 +82,16 @@ func (c *courier) Work(ctx context.Context) error { } } +func (c *courier) UseBackoff(b backoff.BackOff) { + c.backoff = b +} + func (c *courier) watchMessages(ctx context.Context, errChan chan error) { + c.backoff.Reset() for { if err := backoff.Retry(func() error { return c.DispatchQueue(ctx) - }, backoff.NewExponentialBackOff()); err != nil { + }, c.backoff); err != nil { errChan <- err return }