purescript / registry-dev

Development work related to the PureScript Registry
https://github.com/purescript/registry
97 stars 80 forks source link

Replace withBackoff with more explicit alternatives #638

Closed thomashoneyman closed 1 year ago

thomashoneyman commented 1 year ago

There have been a few times in which I mistakenly assumed withBackoff would retry on failure, but that isn't correct: it sets a timeout and cancels the action if it exceeds the timeout, extending the timeout using exponential backoff on each cancellation.

This PR renames withBackoff to withRetryOnTimeout and introduces a new family of withRetry functions that make it easier to retry Aff-based actions on failure. For example, withRetryRequest lets you make an HTTP request and retry when the request succeeds but an error status code was returned.

f-f commented 1 year ago

I have copied the previous iteration of this code in Spago as I didn't want to depend on the Registry app, but maybe I should depend on it? Not sure if we'd like this in lib

thomashoneyman commented 1 year ago

I'd rather not put this in lib because I'd like to be able to arbitrarily change it in the future. It could potentially go in foreign (despite not really being a foreign binding) as Registry.Foreign.Aff and be a collection of Aff utils or something. But I think the best thing is to copy it into Spago and tweak it to your needs.