Module: Turbopuffer::Internal::RespondAsync Private

Defined in:
lib/turbopuffer/internal/respond_async.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Support for transparent polling of async tpuf APIs.

Every API request is stamped with ‘Prefer: respond-async`. If the server applies the preference (i.e. responds with `202 Accepted` + `preference-applied: respond-async`) the SDK polls that URL until the operation finishes and returns the final result as if the API call had been synchronous.

Defined Under Namespace

Classes: Timeout

Constant Summary collapse

HEADER_PREFER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"prefer"
HEADER_PREFERENCE_APPLIED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"preference-applied"
HEADER_LOCATION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"location"
RESPOND_ASYNC =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"respond-async"
POLL_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1.0
POLL_REQUEST_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60.0

Class Method Summary collapse

Class Method Details

.maybe_poll(client, request, response, stream) ⇒ Array(Integer, Net::HTTPResponse, Enumerable<String>)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Array(Integer, Net::HTTPResponse, Enumerable<String>))


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/turbopuffer/internal/respond_async.rb', line 62

def maybe_poll(client, request, response, stream)
  return [Integer(response.code), response, stream] unless respond_async_applied?(response)

  # Drain the original 202 body so the connection returns to the pool.
  stream&.each { next }

  orig_url = request.fetch(:url)
  location = extract_location(orig_url, response)

  timeout = Timeout.new(request.fetch(:timeout))

  loop do
    result = poll_once(client, orig_url, location, timeout)
    return result if result
  end
end

.prepare_headers(headers) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • headers (Hash{String=>String})


52
53
54
# File 'lib/turbopuffer/internal/respond_async.rb', line 52

def prepare_headers(headers)
  headers[HEADER_PREFER] ||= RESPOND_ASYNC
end