Skip to content

Commit

Permalink
Enable rate-throttling by default
Browse files Browse the repository at this point in the history
As a followup from #103 this PR bumps the major platform-api version and enables rate-throttling by default.
  • Loading branch information
schneems committed May 4, 2020
1 parent cae94c5 commit bc0aafe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## 3.0.0

- Rate throttling is on by default.
- Rate throttling is on by default. (https://github.com/heroku/platform-api/pull/104)

## 2.3.0

- Changes are now tracked in the CHANGELOG.md
- Rate throttling is included by default but disabled.
- Changes are now tracked in the CHANGELOG.md.
- Rate throttling is included by default but disabled. (https://github.com/heroku/platform-api/pull/103)
11 changes: 1 addition & 10 deletions config/client-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@
config.module_name = 'PlatformAPI'
config.schema_filepath = File.join(File.expand_path('../..', __FILE__), 'schema.json')

PlatformAPI.rate_throttle = ->(&block) {
@deprecate_on_first ||= begin
message = String.new("[Warning] Starting in PlatformAPI version 3+, requests will include rate throttling logic\n")
message << "to opt-out of this behavior set: `PlatformAPI.rate_throttle = RateThrottleClient::Null.new`\n"
message << "to silence this warning and opt-in to this logic, upgrade to PlatformAPI version 3+"
warn message
true
end
block.call
}
PlatformAPI.rate_throttle = RateThrottleClient::ExponentialIncreaseProportionalRemainingDecrease.new
config.rate_throttle = PlatformAPI.rate_throttle
config.acceptable_status_codes = [429]

Expand Down
2 changes: 1 addition & 1 deletion lib/platform-api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PlatformAPI
VERSION = '2.3.0.pre.1'
VERSION = '3.0.0.pre.1'
end
8 changes: 1 addition & 7 deletions spec/acceptance/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@original_rate_throttle = rate_throttle.dup

# No junk in test dots
rate_throttle.log = ->(*_) {} if rate_throttle.respond_to?("log=")
rate_throttle.log = ->(*_) {}

# Don't sleep in tests
def rate_throttle.sleep(value); end
Expand All @@ -24,8 +24,6 @@ def rate_throttle.sleep(value); end
end

it "works even if first request is rate limited" do
skip("Default behavior changes in v3+") unless Gem::Version.new(PlatformAPI::VERSION) >= Gem::Version.new("3.0.0.beta")

stub_request(:get, "https://api.heroku.com/apps")
.to_return([
{status: 429},
Expand All @@ -46,10 +44,6 @@ def rate_throttle.sleep(value); end
])

@retry_count = 0
throttle = RateThrottleClient::ExponentialIncreaseProportionalRemainingDecrease.new
def throttle.sleep(var); end

PlatformAPI.rate_throttle = throttle
PlatformAPI.rate_throttle.log = ->(*_) { @retry_count += 1 }
client.app.list

Expand Down

0 comments on commit bc0aafe

Please sign in to comment.