Skip to content

Commit

Permalink
fix(courier): add ability to specify backoff (#2349)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Mar 29, 2022
1 parent d950320 commit bf970f3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion courier/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -47,6 +48,7 @@ type (
smtpClient *smtpClient
deps Dependencies
failOnError bool
backoff backoff.BackOff
}
)

Expand All @@ -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(),
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit bf970f3

Please sign in to comment.