Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Server mode needs only a TTL:
client = Schematic::SchematicClient.new(
api_key: ENV["SCHEMATIC_API_KEY"],
credit_leases: {
default_reservation_ttl: 60 * 1000 # how long the server holds the credits if no track settles them (ms, max 1 hour)
default_reservation_ttl: 60 * 1000 # how long the server holds the credits if no track settles them (ms, max 24 hours)
}
)
```
Expand Down
6 changes: 3 additions & 3 deletions lib/schematic/credits/leases/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module Leases

DEFAULT_LEASE_DURATION_MS = 5 * 60 * 1000
DEFAULT_RESERVATION_TTL_MS = 60 * 1000
# The API rejects a hold whose expires_at is more than an hour out, so a
# The API rejects a hold whose expires_at is more than 24 hours out, so a
# larger reservation TTL would fail every server-mode check. The SDK
# clamps to this instead.
MAX_RESERVATION_TTL_MS = 60 * 60 * 1000
# The API measures that hour against its own clock while the SDK computes
MAX_RESERVATION_TTL_MS = 24 * 60 * 60 * 1000
# The API measures that cap against its own clock while the SDK computes
# expires_at against the caller's, so a client running ahead would be
# rejected at exactly the cap. Hold this much back from it.
RESERVATION_TTL_SKEW_ALLOWANCE_MS = 60 * 1000
Expand Down
2 changes: 1 addition & 1 deletion lib/schematic/schematic_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ def resolve_credit_lease_mode(value)
:auto
end

# The API refuses a hold expiring more than an hour after its own clock, and
# The API refuses a hold expiring more than 24 hours after its own clock, and
# this TTL is applied to the caller's, so clamp a step below the cap to leave
# room for skew. Only server mode sends the value to the API: in client mode
# it sizes the local sweep, so clamping there would shorten holds for no
Expand Down
8 changes: 4 additions & 4 deletions test/credits_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1522,10 +1522,10 @@ def test_auto_resolves_per_check_and_falls_to_server_when_the_datastream_goes_aw
client&.close
end

# The API refuses a hold expiring more than an hour out, measured against its
# The API refuses a hold expiring more than 24 hours out, measured against its
# own clock, so a server-mode TTL is clamped a step below the cap.
def test_a_server_mode_reservation_ttl_is_clamped_below_the_api_cap
client = build_client(credit_leases: { mode: :server, default_reservation_ttl: 2 * 60 * 60 * 1000 })
client = build_client(credit_leases: { mode: :server, default_reservation_ttl: 25 * 60 * 60 * 1000 })

assert_equal Leases::MAX_RESERVATION_TTL_MS - Leases::RESERVATION_TTL_SKEW_ALLOWANCE_MS,
client.instance_variable_get(:@server_reservation_ttl_ms)
Expand All @@ -1536,9 +1536,9 @@ def test_a_server_mode_reservation_ttl_is_clamped_below_the_api_cap
# In client mode the TTL sizes the local sweep, so clamping it would shorten
# holds for no reason.
def test_a_client_mode_reservation_ttl_is_left_alone
client = build_client(credit_leases: { mode: :client, default_reservation_ttl: 2 * 60 * 60 * 1000 })
client = build_client(credit_leases: { mode: :client, default_reservation_ttl: 25 * 60 * 60 * 1000 })

assert_equal 2 * 60 * 60 * 1000, client.instance_variable_get(:@server_reservation_ttl_ms)
assert_equal 25 * 60 * 60 * 1000, client.instance_variable_get(:@server_reservation_ttl_ms)
ensure
client&.close
end
Expand Down
Loading