cloudflare / node-cloudflare

Node.js API for Client API
https://cloudflare.github.io/node-cloudflare/
Other
335 stars 92 forks source link

Retry API calls #49

Closed naseemkullah closed 7 months ago

naseemkullah commented 5 years ago

Occasionally we will get a bad request error from an api call to purge the cache. However upon retrying the same request immediately after, it succeeds.

Could a retry policy be implemented directly in the Cloudflare API? For the zones.purgeCache in particular.

terinjokes commented 5 years ago

It would be possible to add, but not currently planned. I don't currently have any way to make most requests to the API idempotent, so it would be unsafe for me to do so automatically.

naseemkullah commented 5 years ago

Sorry, I do not understand the need for idempotency if the API request is only to succeed once? The retry mechanism would only be upon failure of a request after all.

Is that to say there are requests that could be partially complete and then error out?

terinjokes commented 5 years ago

You use the package to submit a request. Most of the time it succeeds and we're all happy.

However it fails. Say your network gets disconnected, or you get a 502 from some HTTP proxy somewhere on Cloudflare's backend, you as the client (and me as the package author) have no way to know if it's been processed or not. Other API have idempotency guarantees (either that retries are safe, or using idempotency keys), but the Cloudflare API does not.

With that mind, it's not the right place for me to make the decision to retry or not.

naseemkullah commented 5 years ago

I see, I see. Could it be user configurable option that defaults to false/0 retries?

terinjokes commented 4 years ago

I plan on exposing this as part of the v3 API.