Class PollingHttpClient<TRequest, TResponse>
- Namespace
 - FoundationaLLM.Common.Clients
 
- Assembly
 - FoundationaLLM.Common.dll
 
Provides a generic HTTP client that can be used to poll for a response.
public class PollingHttpClient<TRequest, TResponse> where TRequest : CompletionRequestBase where TResponse : CompletionResponseBase
  Type Parameters
TRequestThe type of the payload to send to start the operation.
TResponseThe type of the response received when the operation is completed.
- Inheritance
 - 
      
      PollingHttpClient<TRequest, TResponse>
 
- Inherited Members
 
- Extension Methods
 
Constructors
PollingHttpClient(HttpClient, HttpClient, TRequest?, string, string, TimeSpan, TimeSpan, ILogger)
Provides a generic HTTP client that can be used to poll for a response.
public PollingHttpClient(HttpClient operationStarterHttpClient, HttpClient operationRetrieverHttpClient, TRequest? request, string operationStarterPath, string operationRetrieverPathTemplate, TimeSpan pollingInterval, TimeSpan maxWaitTime, ILogger logger)
  Parameters
operationStarterHttpClientHttpClientThe HttpClient used to start the operation.
operationRetrieverHttpClientHttpClientThe HttpClient used to retrieve the operation (including its status).
requestTRequestThe
TRequestrequest to send to the service.operationStarterPathstringThe path used to start the operation.
operationRetrieverPathTemplatestringThe path template used to retrieve the operation (including its status).
pollingIntervalTimeSpanThe TimeSpan interval to poll for the response.
maxWaitTimeTimeSpanThe TimeSpan maximum time to wait for the response.
loggerILoggerThe logger used for logging.
Methods
ExecuteOperationAsync(CancellationToken)
Executes an operation and waits for the response using a polling mechanism. The polling mechanism is based on the following assumptions:
- The {operationStarterPath} endpoint will accept a POST with aTRequest object as payload and will return a 202 Accepted status code when the operation is started.- The returned response will contain a LongRunningOperation object with the operation id.
- The polling endpoint is available at {operationStarterPath}/{operationId}/status.
- The polling endpoint will return a 200 status code when the operation is found.
- The returned response will contain a LongRunningOperation object with the current status of the operation, possibly including the result if the operation completed.
- The polling endpoint will return a 404 Not Found status code when the operation is not found.
public Task<TResponse?> ExecuteOperationAsync(CancellationToken cancellationToken = default)
  Parameters
cancellationTokenCancellationTokenThe CancellationToken indicating the need to cancel the process.
Returns
- Task<TResponse>
 The
TResponseobject containing the response.
Exceptions
GetOperationStatusAsync(string, CancellationToken)
Gets the status of a running operation.
public Task<LongRunningOperation> GetOperationStatusAsync(string operationId, CancellationToken cancellationToken = default)
  Parameters
operationIdstringThe identifier of the running operation.
cancellationTokenCancellationTokenThe CancellationToken indicating the need to cancel the process.
Returns
- Task<LongRunningOperation>
 A LongRunningOperationobject providing details about the running operation.
StartOperationAsync(CancellationToken)
Starts an operation and returns immediately.
public Task<LongRunningOperation> StartOperationAsync(CancellationToken cancellationToken = default)
  Parameters
cancellationTokenCancellationTokenThe CancellationToken indicating the need to cancel the process.
Returns
- Task<LongRunningOperation>
 A LongRunningOperationobject providing details about the newly started operation.