This demo is created for Festive Tech Calendar 2023.
Santa Claus is using Dapr to ensure everyone gets their Christmas gift on time. He has a large team of elves who are responsible for different tasks such as making toys, wrapping gifts, and loading the sleigh. Each task is an activity that can be executed by one or more elves. Santa needs to coordinate the activities of all the elves in a reliable and efficient way.
That's where Dapr Workflow comes in. Santa defines his workflow in code (he prefers C#, but Python or Java can also be used) where he specifies the sequence of the activities. Dapr Workflow takes care of the orchestration logic, fault tolerance, and scalability of the workflow, so Santa can focus on the business logic and is assured of optimal elf efficiency.
This diagram shows an overview of the various workflows and activities that Santa is using to orchestrate the activities of his elves.
graph TD;
subgraph SantaClausWorkflow
Start((Start:\n list of wishes))
CW[Start ChristmasWishWorkflow]
subgraph ChristmasWishWorkflow
NNA[NaughtyOrNiceActivity]
RWA[RegisterWishActivity]
AWA[AssignWorkbenchActivity]
Choose{ChooseWorkflow\nbased on GiftType}
BW[BookWorkflow]
WW[WoodenToyWorkflow]
CEAW[CatalystEarlyAccessWorkflow]
WA[WrapActivity]
PGA[PutGiftInSleighActivity]
end
Deliver[DeliverGiftsActivity]
End((End))
end
Start-->|For each wish in the list|CW;
CW-->NNA
NNA-->|Is nice|RWA
NNA-->|Is naughty|End
RWA-->AWA
AWA-->Choose
Choose-->|GiftType=book|BW;
Choose-->|GiftType=wooden toy|WW;
Choose-->|GiftType=Catalyst early access|CEAW;
BW-->WA
WW-->WA
CEAW-->WA
WA-->PGA
PGA-->Deliver
Deliver-->End
These are the workflows Santa is using:
- SantaClausWorkflow: The main workflow that takes an array of wishes and starts a child workflow (ChristmasWishWorkflow) for each of the wishes.
- ChristmasWishWorkflow: This workflow contains activities to check if the person is naughty or nice, and if they are nice, a gift is selected and registered for that person. Based on the type of gift, another child workflow (BookWorkflow, WoodenToyWorkflow, CatalystEarlyAccessWorkflow) is started to make the gift. Once that child workflow is finished, activities are called to wrap the gift and load it into the sleigh.
- BookWorkflow: This workflow contains activities to prepare a book as a gift.
- WoodenToyWorkflow: This workflow contains activities to build a wooden toy. It calls activities to lookup the parts, assemble the parts, and paint the toy.
- CatalystEarlyAccessWorkflow: This workflow contains one activity that returns a link to get early access to Diagrid Catalyst, so they can make complex architectures simple, reliable and secure with APIs that connect to their existing infrastructure and work with their existing code.
Click to expand the BookWorkflow
diagram
graph TD;
Start((Start))-->DetermineBookContentActivity
subgraph fan-out/fan-in for each part in the book
WritePageActivity
end
DetermineBookContentActivity-->WritePageActivity
WritePageActivity-->BindBookActivity
BindBookActivity-->End((End))
Click to expand the WoodenToyWorkflow
diagram
graph TD;
Start((Start))-->LookupPartsActivity
subgraph fan-out/fan-in for each part of the toy
CollectPartActivity
end
LookupPartsActivity-->CollectPartActivity
CollectPartActivity-->AssembleToyActivity
AssembleToyActivity-->PaintToyActivity
PaintToyActivity-->End((End))
Click to expand the CatalystEarlyAccessWorkflow
diagram
graph TD;
Start((Start))-->CatalystEarlyAccessActivity
CatalystEarlyAccessActivity-->End((End))
- .NET 7 SDK
- Docker Desktop
- Dapr CLI
- Ensure that you're using v1.12 (or higher) of the Dapr runtime and the CLI.
- A REST client, such as cURL, or the VSCode REST client extension.
To run the SantaWorkflow:
-
Build the solution:
dotnet build
-
Use the Dapr CLI to run the web app with the workflows (ensure that Docker is running):
dapr run -f .
-
Use the HTTP endpoints in the local-workflow-test.http file to start the workflow and check the status.
Start the workflow:
@app_url=http://localhost:5065 // @name startRequest POST {{app_url}}/start Content-Type: application/json [ { "Name" : "Alex", "GiftType" : "WoodenToy" }, { "Name" : "Rene", "GiftType" : "Book" }, { "Name" : "Robin", "GiftType" : "CatalystEarlyAccess" } ]
Get the workflow status:
@dapr_url=http://localhost:3500 @instanceId={{startRequest.response.body.*}} GET {{dapr_url}}/v1.0-beta1/workflows/dapr/{{instanceId}}