How to modify Faraday middleware configuration on a per-request basis?

230 Views Asked by At

I've got some well-configured Faraday client:

client = Faraday.new(url: base_url) do |f|
  f.request :retry, { max: 3, backoff_factor: 2 }
  f.request :authorization, 'Bearer', -> { access_token }
  f.request :json
  f.response :json
  f.response :raise_error
end

and for the most part it's great, but now I've got this one weird case where I want to retry on an apparently successful request because I'm waiting for data to propagate, so I want to do something like:

client(
 retry_options: {
   max: 10,
   retry_if: -> (env, _exc) { 
     env.body[:data][:ready] == false
   }
).get("/wait-for-data")

The idea being that for this specific request, I want to modify the existing configuration for the retry middleware, so that it'll "fail", and retry with the backoff many more times.

I'm not finding anything, but I'm also getting pretty poor Google results looking for insight. Can anyone point me at some ways to accomplish this?

0

There are 0 best solutions below