cenkalti/backoff

Notification function as interface of BackOffs.

thediveo opened this issue · 0 comments

At this time, backoff supports the usecase well, where the code calling RetryNotify(b, n) is either directly related to the notification function passed or at least got it passed in explicitly along with a particular backoff.

When RetryNotify(...) is deeper in a layered architecture then a higher layer or the upmost layer might be interested in notifications instead, as it is the ultimate consumer as well as the originator of the backoff. In order to avoid having all intermediate layers having to be made aware of notification callbacks, would it be possible to attach notification callbacks to the backoff objects themselves?

This would allow the source of backoff information to also be able to get ultimately informed about any retries without much hassle.

Some use cases might be service logging by the ultimate service as to not having to instrument lower layer modules with logging and specific loggers (a nightmare in itself), as well as easy uni test instrumentation.

    cbo := NewConstantBackOff(42*time.Seconds, WithNotify(func(){ /* ... */ }))
    ebo := NewExponentialBackOff(WithNotify(func(){ /* ... */ }))

This might be easier to achieve in terms of API with the "builder pattern" issue #106 in place.