Class: Hatchet::ShellThrottle
- Inherits:
-
Object
- Object
- Hatchet::ShellThrottle
- Defined in:
- lib/hatchet/shell_throttle.rb
Overview
A class for throttling non-http resources
Non-http calls can be rate-limited for example shell calls to ‘heroku run ` and `git push heroku` this class provides an easy interface to leverage the rate throttling behavior baked into `PlatformAPI` for calls things that do not have a real associated web request
Example:
output = ""
ShellThrottle.new(platform_api: @platform_api).call
output = `git push heroku main`
throw(:throttle) if output.match?(/reached the API rate limit/)
end
puts output
In this example ‘git push heroku main` will retry and backoff until the output no longer matches `reached the API rate limit`.
Defined Under Namespace
Classes: FakeResponse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(platform_api:) ⇒ ShellThrottle
constructor
A new instance of ShellThrottle.
Constructor Details
#initialize(platform_api:) ⇒ ShellThrottle
Returns a new instance of ShellThrottle.
20 21 22 |
# File 'lib/hatchet/shell_throttle.rb', line 20 def initialize(platform_api: ) @platform_api = platform_api end |
Instance Method Details
#call ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hatchet/shell_throttle.rb', line 24 def call out = nil PlatformAPI.rate_throttle.call do catch(:throttle) do out = yield return end try_again end return out end |