Skip to content

Commit

Permalink
Merge pull request #1859 from solliancenet/cj-polling-stop-condition-082
Browse files Browse the repository at this point in the history
(0.8.2) Add termination condition for completion status
  • Loading branch information
codingbandit authored Oct 12, 2024
2 parents 6adbbc5 + 16ef6d0 commit 167f71c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/dotnet/Core/Services/CoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ public async Task<Message> GetCompletionOperationStatus(string instanceId, strin
var operationContext = await _cosmosDBService.GetLongRunningOperationContextAsync(operationId);
var operationStatus = await GetDownstreamAPIService(operationContext.GatekeeperOverride).GetCompletionOperationStatus(instanceId, operationId);

if ((DateTime.UtcNow - operationContext.StartTime).TotalMinutes > 30
&& (operationStatus.Status == OperationStatus.Pending || operationStatus.Status == OperationStatus.InProgress))
{
// We've hit the hard stop time for the operation.

await _cosmosDBService.PatchSessionsItemPropertiesAsync<Message>(
operationContext.AgentMessageId,
operationContext.SessionId,
new Dictionary<string, object?>
{
{ "/status", OperationStatus.Failed },
{ "/text", "The completion operation has exceeded the maximum time allowed." }
});

return new Message
{
OperationId = operationId,
Status = OperationStatus.Failed,
Text = "The completion operation has exceeded the maximum time allowed."
};
}

if (operationStatus.Result is JsonElement jsonElement)
{
var completionResponse = jsonElement.Deserialize<CompletionResponse>();
Expand Down

0 comments on commit 167f71c

Please sign in to comment.