Skip to content

Commit

Permalink
Implement sandbox rate limits
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Sep 19, 2024
1 parent d32fb4f commit a292282
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/peddler/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def http
# @param [Float] delay The delay in seconds before retrying
# @return [self]
def rate_limit(rate)
# HTTP v6.0 will implement retriable
# HTTP v6.0 will implement retriable. Until then, point to their GitHub repo, or it's a no-op.
# https://github.com/httprb/http/pull/790
retriable(delay: 1.0 / rate, retry_statuses: [429]) if @http.respond_to?(:retriable)
delay = sandbox? ? 0.2 : 1.0 / rate
retriable(delay: delay, retry_statuses: [429]) if @http.respond_to?(:retriable)

self
end

Expand Down
4 changes: 4 additions & 0 deletions test/peddler/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def test_custom_rate_limit
skip("HTTP v6.0 not released yet")
end

def test_sandbox_rate_limit
skip("HTTP v6.0 not released yet")
end

def test_client_error
assert_raises(Peddler::Error) do
@api.post("/")
Expand Down

0 comments on commit a292282

Please sign in to comment.