class Hatchet::ShellThrottle
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`.
Public Class Methods
new(platform_api: )
click to toggle source
# File lib/hatchet/shell_throttle.rb, line 20 def initialize(platform_api: ) @platform_api = platform_api end
Public Instance Methods
call() { || ... }
click to toggle source
# 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
Private Instance Methods
remaining()
click to toggle source
# File lib/hatchet/shell_throttle.rb, line 45 def remaining @platform_api.rate_limit.info["remaining"] end
success()
click to toggle source
# File lib/hatchet/shell_throttle.rb, line 37 def success FakeResponse.new(status: 200, remaining: remaining) end
try_again()
click to toggle source
# File lib/hatchet/shell_throttle.rb, line 41 def try_again FakeResponse.new(status: 429, remaining: remaining) end