Skip to content

Commit

Permalink
Merge pull request #959 from MregXN/remove-daprClient-for-workflow
Browse files Browse the repository at this point in the history
use daprWorkflowClient instead of daprClient in workflow sample
  • Loading branch information
paulyuk authored Feb 11, 2024
2 parents d718efe + 0453824 commit a933afe
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions workflows/csharp/sdk/order-processor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@

using var daprClient = new DaprClientBuilder().Build();

// NOTE: WorkflowEngineClient will be replaced with a richer version of DaprClient
// in a subsequent SDK release. This is a temporary workaround.
WorkflowEngineClient workflowClient = host.Services.GetRequiredService<WorkflowEngineClient>();
DaprWorkflowClient workflowClient = host.Services.GetRequiredService<DaprWorkflowClient>();

// Generate a unique ID for the workflow
string orderId = Guid.NewGuid().ToString()[..8];
Expand All @@ -51,28 +49,25 @@
// Start the workflow
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);

await daprClient.StartWorkflowAsync(
workflowComponent: DaprWorkflowComponent,
workflowName: nameof(OrderProcessingWorkflow),
input: orderInfo,
instanceId: orderId);
await workflowClient.ScheduleNewWorkflowAsync(
name: nameof(OrderProcessingWorkflow),
instanceId: orderId,
input: orderInfo);

// Wait for the workflow to start and confirm the input
GetWorkflowResponse state = await daprClient.WaitForWorkflowStartAsync(
instanceId: orderId,
workflowComponent: DaprWorkflowComponent);
WorkflowState state = await workflowClient.WaitForWorkflowStartAsync(
instanceId: orderId);

Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", state.RuntimeStatus);
Console.WriteLine("Your workflow has started. Here is the status of the workflow: {0}", Enum.GetName(typeof(WorkflowRuntimeStatus), state.RuntimeStatus));

// Wait for the workflow to complete
state = await daprClient.WaitForWorkflowCompletionAsync(
instanceId: orderId,
workflowComponent: DaprWorkflowComponent);
state = await workflowClient.WaitForWorkflowCompletionAsync(
instanceId: orderId);

Console.WriteLine("Workflow Status: {0}", state.RuntimeStatus);
Console.WriteLine("Workflow Status: {0}", Enum.GetName(typeof(WorkflowRuntimeStatus), state.RuntimeStatus));

void RestockInventory(string itemToPurchase)
{
daprClient.SaveStateAsync<OrderPayload>(StoreName, itemToPurchase, new OrderPayload(Name: itemToPurchase, TotalCost: 15000, Quantity: 100));
daprClient.SaveStateAsync<OrderPayload>(StoreName, itemToPurchase, new OrderPayload(Name: itemToPurchase, TotalCost: 15000, Quantity: 100));
return;
}

0 comments on commit a933afe

Please sign in to comment.