You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using faraday in a background job via ActiveJob. I would like to conditionally sleep inline depending on how large the 429 retry-after header's value is. If the value is sufficiently large, I want to re-raise the error and have ActiveJob catch it and reschedule the job in the future, using the retry-after header from the exception.
But, I can't see how to tell faraday-retry that I want to re-raise an error. It seems that faraday will wait after the retry block anyway.
Actual behavior
error is not re-raised
Expected behavior
error is re-raised.
Steps to reproduce
I don't know of a way to easily reproduce because httpbin doesn't return a retry-after header, but here's the general idea:
#!/usr/bin/env ruby# frozen_string_literal: truerequire"bundler/inline"gemfiledosource"https://rubygems.org"gem"faraday"gem"faraday-retry"endretry_options={max: 1,exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::TooManyRequestsError],retry_block: ->(env:,options:,retry_count:,exception:,will_retry_in:){ifexception.is_a?(Faraday::TooManyRequestsError)retry_after=exception.response[:headers]["retry-after"].to_iifretry_after < 10sleepretry_afterelse# This will be caught at the top level and used to reschedule the job# in the futureraise(exception)endend},}faraday=Faraday.newdo |conn|
conn.request:retry, **retry_optionsendfaraday.get("https://httpbin.org/status/429")
Thanks
The text was updated successfully, but these errors were encountered:
Basic Version Info
Faraday Version: 2.9.0
Ruby Version: 3.2.2
Issue description
I'm using faraday in a background job via ActiveJob. I would like to conditionally sleep inline depending on how large the 429 retry-after header's value is. If the value is sufficiently large, I want to re-raise the error and have ActiveJob catch it and reschedule the job in the future, using the retry-after header from the exception.
But, I can't see how to tell faraday-retry that I want to re-raise an error. It seems that faraday will wait after the retry block anyway.
Actual behavior
error is not re-raised
Expected behavior
error is re-raised.
Steps to reproduce
I don't know of a way to easily reproduce because httpbin doesn't return a retry-after header, but here's the general idea:
Thanks
The text was updated successfully, but these errors were encountered: