JamesIves/fetch-api-data-action

Retry fetch option for intermittent API errors

beornf opened this issue · 6 comments

Excellent github action! I'm using your action to cache an external API which is secured with OAuth.

This API often experiences issues: There was an error fetching from the API: FetchError: invalid json response body at https://example.com reason: Unexpected end of JSON input.

By retrying the same request in a few seconds the error will usually go away. I propose adding an option that allows failed requests to be retried N times waiting M seconds between requests.

Thanks for the request.

Is the intention for this to only fire if the API throws an error? Additionally should the re-try occur on the entire flow, or just the API that produced said error? For example if you make a token request, and that fails, it try's again x times, and then continues to the next, and then the same thing occurs with the data endpoint if that encounters an error?

I'd prefer to cap the limit of how many retries that can occur in order to simplify the action. Do you feel 3 would be sufficient with a 5 or 10 second wait period? That way you can just toggle RETRY: true and then it would handle everything for you instead of configuring the time and attempt limit.

Lemme know your thoughts.

Yes the intention is to retry only for the API that throws an error. If the token request succeeds and the data request fails the access token is still valid, thus only the data request should be retried N times.

A global retry limit of 3 would be acceptable. Increasing wait periods of 5, 10 and 15 seconds is one possible retry strategy or a constant wait time of 10 seconds would be equivalent.

I agree with some reasonable defaults having a single RETRY: true option would be best for the user.

I'll do my best to get this up in the next couple of days.

@beornf I've still got a couple of things to wrap up with this before it gets released, but if you'd like to test the functionality you can use JamesIves/fetch-api-data-action@releases/v1-test and set RETRY: true within your workflow configuration.

I've done unit testing on JamesIves/fetch-api-data-action@releases/v1-test and it works great. The retry module is neat with random exponential delay. Thanks @JamesIves! 🥇

Great! Here's the release, it's now available within releases/v1 branch.

https://github.com/JamesIves/fetch-api-data-action/releases/tag/1.0.5

Thanks for your help testing!