Exception: Parse::Embeddings::SpendCap::Exceeded

Inherits:
StandardError
  • Object
show all
Defined in:
lib/parse/embeddings/spend_cap.rb

Overview

Raised when a tenant would exceed its token cap. Carries the limit, the already-used count (within the window), and a retry_after hint (seconds until enough of the window rolls off to admit the rejected charge — nil if the charge can never fit).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tenant_id:, limit:, used:, requested:, window:, retry_after:) ⇒ Exceeded

Returns a new instance of Exceeded.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/parse/embeddings/spend_cap.rb', line 47

def initialize(tenant_id:, limit:, used:, requested:, window:, retry_after:)
  @tenant_id = tenant_id
  @limit = limit
  @used = used
  @requested = requested
  @window = window
  @retry_after = retry_after
  super(
    "Embedding spend cap exceeded for tenant #{tenant_id.inspect}: " \
    "#{used}+#{requested} tokens would exceed #{limit}/#{window}s." \
    "#{retry_after ? " Retry after #{retry_after.round(1)}s." : " Request exceeds the cap outright."}"
  )
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def limit
  @limit
end

#requestedObject (readonly)

Returns the value of attribute requested.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def requested
  @requested
end

#retry_afterObject (readonly)

Returns the value of attribute retry_after.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def retry_after
  @retry_after
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def tenant_id
  @tenant_id
end

#usedObject (readonly)

Returns the value of attribute used.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def used
  @used
end

#windowObject (readonly)

Returns the value of attribute window.



45
46
47
# File 'lib/parse/embeddings/spend_cap.rb', line 45

def window
  @window
end