mirror of https://github.com/dapr/quickstarts.git
use daprWorkflowClient
Signed-off-by: MregXN <mregxn@gmail.com>
This commit is contained in:
parent
c7f5100b0a
commit
04538247a0
|
|
@ -33,9 +33,7 @@ host.Start();
|
||||||
|
|
||||||
using var daprClient = new DaprClientBuilder().Build();
|
using var daprClient = new DaprClientBuilder().Build();
|
||||||
|
|
||||||
// NOTE: WorkflowEngineClient will be replaced with a richer version of DaprClient
|
DaprWorkflowClient workflowClient = host.Services.GetRequiredService<DaprWorkflowClient>();
|
||||||
// in a subsequent SDK release. This is a temporary workaround.
|
|
||||||
WorkflowEngineClient workflowClient = host.Services.GetRequiredService<WorkflowEngineClient>();
|
|
||||||
|
|
||||||
// Generate a unique ID for the workflow
|
// Generate a unique ID for the workflow
|
||||||
string orderId = Guid.NewGuid().ToString()[..8];
|
string orderId = Guid.NewGuid().ToString()[..8];
|
||||||
|
|
@ -51,28 +49,25 @@ OrderPayload orderInfo = new OrderPayload(itemToPurchase, 15000, ammountToPurcha
|
||||||
// Start the workflow
|
// Start the workflow
|
||||||
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);
|
Console.WriteLine("Starting workflow {0} purchasing {1} {2}", orderId, ammountToPurchase, itemToPurchase);
|
||||||
|
|
||||||
await daprClient.StartWorkflowAsync(
|
await workflowClient.ScheduleNewWorkflowAsync(
|
||||||
workflowComponent: DaprWorkflowComponent,
|
name: nameof(OrderProcessingWorkflow),
|
||||||
workflowName: nameof(OrderProcessingWorkflow),
|
instanceId: orderId,
|
||||||
input: orderInfo,
|
input: orderInfo);
|
||||||
instanceId: orderId);
|
|
||||||
|
|
||||||
// Wait for the workflow to start and confirm the input
|
// Wait for the workflow to start and confirm the input
|
||||||
GetWorkflowResponse state = await daprClient.WaitForWorkflowStartAsync(
|
WorkflowState state = await workflowClient.WaitForWorkflowStartAsync(
|
||||||
instanceId: orderId,
|
instanceId: orderId);
|
||||||
workflowComponent: DaprWorkflowComponent);
|
|
||||||
|
|
||||||
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
|
// Wait for the workflow to complete
|
||||||
state = await daprClient.WaitForWorkflowCompletionAsync(
|
state = await workflowClient.WaitForWorkflowCompletionAsync(
|
||||||
instanceId: orderId,
|
instanceId: orderId);
|
||||||
workflowComponent: DaprWorkflowComponent);
|
|
||||||
|
|
||||||
Console.WriteLine("Workflow Status: {0}", state.RuntimeStatus);
|
Console.WriteLine("Workflow Status: {0}", Enum.GetName(typeof(WorkflowRuntimeStatus), state.RuntimeStatus));
|
||||||
|
|
||||||
void RestockInventory(string itemToPurchase)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue