Skip to content

Commit

Permalink
Create long running operation with OperationId passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
codingbandit committed Jul 26, 2024
1 parent 26ef028 commit c2378a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/dotnet/State/Interfaces/IStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public interface IStateService
/// <summary>
/// Creates a new long-running operation with default values.
/// </summary>
/// <param name="operationId">The long-running operation identifier.</param>
/// <returns></returns>
Task<LongRunningOperation> CreateLongRunningOperation();
Task<LongRunningOperation> CreateLongRunningOperation(string operationId);

/// <summary>
/// Inserts or updates the result of a long-running operation.
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/State/Services/StateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public async Task<List<LongRunningOperationLogEntry>> GetLongRunningOperationLog
}

/// <inheritdoc/>
public async Task<LongRunningOperation> CreateLongRunningOperation()
public async Task<LongRunningOperation> CreateLongRunningOperation(string operationId)
{
logger.LogInformation("Creating long running operation.");
var operation = new LongRunningOperation
{
Status = OperationStatus.Pending,
OperationId = Guid.NewGuid().ToString()
OperationId = operationId
};
return await cosmosDbService.UpsertLongRunningOperation(operation);
}
Expand Down
8 changes: 4 additions & 4 deletions src/dotnet/StateAPI/Controllers/OperationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public async Task<IActionResult> GetLongRunningOperationLogs(string instanceId,
/// <summary>
/// Inserts a long-running operation and creates a log entry.
/// </summary>
/// <param name="operationId">The ID of the long running operation.</param>
/// <param name="instanceId">The FoundationaLLM instance ID.</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> CreateLongRunningOperation(string instanceId)
[HttpPost("{operationId}")]
public async Task<IActionResult> CreateLongRunningOperation(string instanceId, string operationId)
{
var createdLongRunningOperation = await stateService.CreateLongRunningOperation();

var createdLongRunningOperation = await stateService.CreateLongRunningOperation(operationId);
return new OkObjectResult(createdLongRunningOperation);
}

Expand Down

0 comments on commit c2378a3

Please sign in to comment.