1.9 KiB
Monitor Pattern
This tutorial demonstrates how to run a workflow in a loop. This can be used for recurring tasks that need to be executed on a certain frequency (e.g. a clean-up job that runs every hour). For more information on the monitor pattern see the Dapr docs.
Inspect the code
Open the MonitorWorkflow.cs file in the tutorials/workflow/csharp/monitor-pattern/Monitor folder. This file contains the definition for the workflow.
graph LR
SW((Start
Workflow))
CHECK[CheckStatus]
IF{Is Ready}
TIMER[Wait for a period of time]
NEW[Continue as a new instance]
EW((End
Workflow))
SW --> CHECK
CHECK --> IF
IF -->|Yes| EW
IF -->|No| TIMER
TIMER --> NEW
NEW --> SW
Run the tutorial
-
Use a terminal to navigate to the
tutorials/workflow/csharp/monitor-patternfolder. -
Build the project using the .NET CLI.
dotnet build ./Monitor/ -
Use the Dapr CLI to run the Dapr Multi-App run file
```bashdapr run -f .
<!-- END_STEP --> -
Use the POST request in the
monitor.httpfile to start the workflow.The input for the workflow is an integer with the value
0. -
Use the GET request in the
monitor.httpfile to get the status of the workflow.The expected serialized output of the workflow is:
"\"Status is healthy after checking 3 times.\""The actual number of checks can vary since some randomization is used in the
CheckStatusactivity. -
Stop the Dapr Multi-App run process by pressing
Ctrl+C.