Skip to content

Commit 74cdaa0

Browse files
committed
Adds dapr workflow docs
Based on dapr/cli#1560 Signed-off-by: joshvanl <[email protected]>
1 parent 9df106b commit 74cdaa0

File tree

8 files changed

+749
-1
lines changed

8 files changed

+749
-1
lines changed

daprdocs/content/en/developing-applications/building-blocks/workflow/howto-author-workflow.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,46 @@ Because of how replay-based workflows execute, you'll write logic that does thin
11791179
11801180
{{% /alert %}}
11811181
1182+
## Testing Your Workflow
1183+
1184+
After authoring your workflow, test it using the Dapr CLI:
1185+
1186+
### Start Your Workflow
1187+
1188+
```bash
1189+
dapr workflow run OrderProcessingWorkflow \
1190+
--app-id orderservice \
1191+
--input '{"orderId": "test-001", "items": [{"sku": "WIDGET", "quantity": 5}]}'
1192+
```
1193+
1194+
### Monitor Workflow Execution
1195+
1196+
```bash
1197+
dapr workflow list --app-id orderservice --filter-status RUNNING
1198+
```
1199+
1200+
### Test External Events
1201+
1202+
```bash
1203+
# Raise an event your workflow is waiting for
1204+
dapr workflow raise-event <instance-id>/ApprovalReceived \
1205+
--app-id orderservice \
1206+
--input '{"approved": true, "approver": "[email protected]"}'
1207+
```
1208+
1209+
### Debug Failed Workflows
1210+
1211+
```bash
1212+
# List failed workflows
1213+
dapr workflow list --app-id orderservice --filter-status FAILED --output wide
1214+
1215+
# Get detailed history of a failed workflow
1216+
dapr workflow history <failed-instance-id> --app-id orderservice --output json
1217+
1218+
# Re-run the workflow after fixing issues
1219+
dapr workflow rerun <failed-instance-id> --app-id orderservice
1220+
```
1221+
11821222
## Next steps
11831223
11841224
Now that you've authored a workflow, learn how to manage it.

daprdocs/content/en/developing-applications/building-blocks/workflow/howto-manage-workflow.md

Lines changed: 277 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,286 @@ weight: 6000
66
description: Manage and run workflows
77
---
88

9-
Now that you've [authored the workflow and its activities in your application]({{% ref howto-author-workflow.md %}}), you can start, terminate, and get information about the workflow using HTTP API calls. For more information, read the [workflow API reference]({{% ref workflow_api.md %}}).
9+
Now that you've [authored the workflow and its activities in your application]({{% ref howto-author-workflow.md %}}), you can start, terminate, and get information about the workflow using the CLI or API calls. For more information, read the [workflow API reference]({{% ref workflow_api.md %}}).
1010

1111
{{< tabpane text=true >}}
1212

13+
<!--CLI-->
14+
{{% tab "CLI" %}}
15+
16+
## Managing Workflows with the Dapr CLI
17+
18+
The Dapr CLI provides powerful commands for managing workflow instances in both self-hosted and Kubernetes environments.
19+
20+
### Prerequisites
21+
22+
- Dapr CLI version 1.16.2 or later
23+
- A running Dapr application with workflows configured
24+
- For database operations: network access to your actor state store
25+
26+
### Basic Workflow Operations
27+
28+
#### Start a Workflow
29+
30+
```bash
31+
# Start a workflow with input data
32+
dapr workflow run OrderProcessingWorkflow \
33+
--app-id orderprocessing \
34+
--input '{"orderId": "12345", "amount": 100.50}'
35+
36+
# Start with a specific instance ID
37+
dapr workflow run OrderProcessingWorkflow \
38+
--app-id orderprocessing \
39+
--instance-id order-12345 \
40+
--input '{"orderId": "12345"}'
41+
42+
# Schedule a workflow to start later
43+
dapr workflow run OrderProcessingWorkflow \
44+
--app-id orderprocessing \
45+
--start-time "2024-12-25T10:00:00Z"
46+
```
47+
48+
#### List Workflow Instances
49+
50+
```bash
51+
# List all workflows for an app
52+
dapr workflow list --app-id orderprocessing
53+
54+
# Filter by status
55+
dapr workflow list --app-id orderprocessing --filter-status RUNNING
56+
57+
# Filter by workflow name
58+
dapr workflow list --app-id orderprocessing --filter-name OrderProcessingWorkflow
59+
60+
# Filter by age (workflows started in last 24 hours)
61+
dapr workflow list --app-id orderprocessing --filter-max-age 24h
62+
63+
# Get detailed output
64+
dapr workflow list --app-id orderprocessing --output wide
65+
```
66+
67+
#### View Workflow History
68+
69+
```bash
70+
# Get execution history
71+
dapr workflow history order-12345 --app-id orderprocessing
72+
73+
# Get history in JSON format
74+
dapr workflow history order-12345 --app-id orderprocessing --output json
75+
```
76+
77+
#### Control Workflow Execution
78+
79+
```bash
80+
# Suspend a running workflow
81+
dapr workflow suspend order-12345 \
82+
--app-id orderprocessing \
83+
--reason "Waiting for manual approval"
84+
85+
# Resume a suspended workflow
86+
dapr workflow resume order-12345 \
87+
--app-id orderprocessing \
88+
--reason "Approved by manager"
89+
90+
# Terminate a workflow
91+
dapr workflow terminate order-12345 \
92+
--app-id orderprocessing \
93+
--output '{"reason": "Cancelled by customer"}'
94+
```
95+
96+
#### Raise External Events
97+
98+
```bash
99+
# Raise an event for a waiting workflow
100+
dapr workflow raise-event order-12345/PaymentReceived \
101+
--app-id orderprocessing \
102+
--input '{"paymentId": "pay-67890", "amount": 100.50}'
103+
```
104+
105+
#### Re-run Workflows
106+
107+
```bash
108+
# Re-run from the beginning
109+
dapr workflow rerun order-12345 --app-id orderprocessing
110+
111+
# Re-run from a specific event
112+
dapr workflow rerun order-12345 \
113+
--app-id orderprocessing \
114+
--event-id 5
115+
116+
# Re-run with a new instance ID
117+
dapr workflow rerun order-12345 \
118+
--app-id orderprocessing \
119+
--new-instance-id order-12345-retry
120+
```
121+
122+
#### Purge Completed Workflows
123+
124+
```bash
125+
# Purge a specific instance
126+
dapr workflow purge order-12345 --app-id orderprocessing
127+
128+
# Purge all completed workflows older than 30 days
129+
dapr workflow purge --app-id orderprocessing --all-older-than 720h
130+
131+
# Purge all terminal workflows (use with caution!)
132+
dapr workflow purge --app-id orderprocessing --all
133+
```
134+
135+
### Kubernetes Operations
136+
137+
All commands support the `-k` flag for Kubernetes deployments:
138+
139+
```bash
140+
# List workflows in Kubernetes
141+
dapr workflow list \
142+
--kubernetes \
143+
--namespace production \
144+
--app-id orderprocessing
145+
146+
# Suspend a workflow in Kubernetes
147+
dapr workflow suspend order-12345 \
148+
--kubernetes \
149+
--namespace production \
150+
--app-id orderprocessing \
151+
--reason "Maintenance window"
152+
```
153+
154+
### Advanced: Direct Database Access
155+
156+
For advanced operations like listing and purging workflows, you can connect directly to the actor state store database. This is useful for:
157+
158+
- Querying workflows across multiple app instances
159+
- Bulk operations on workflow metadata
160+
- Custom filtering beyond what the API provides
161+
162+
#### Self-Hosted Mode
163+
164+
In self-hosted mode, the CLI can automatically discover your state store configuration:
165+
166+
```bash
167+
# The CLI reads your component configuration automatically
168+
dapr workflow list --app-id orderprocessing
169+
```
170+
171+
To override with a specific connection string:
172+
173+
```bash
174+
# PostgreSQL
175+
dapr workflow list \
176+
--app-id orderprocessing \
177+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
178+
--table-name workflows
179+
180+
# MySQL
181+
dapr workflow list \
182+
--app-id orderprocessing \
183+
--connection-string "dapr:dapr@tcp(localhost:3306)/dapr?parseTime=true" \
184+
--table-name workflows
185+
186+
# SQL Server
187+
dapr workflow list \
188+
--app-id orderprocessing \
189+
--connection-string "sqlserver://dapr:Pass@word1@localhost:1433?database=dapr" \
190+
--table-name workflows
191+
```
192+
193+
#### Kubernetes Mode with Port Forwarding
194+
195+
In Kubernetes, you need to establish connectivity to your database:
196+
197+
**Step 1: Port forward to your database service**
198+
199+
```bash
200+
# PostgreSQL
201+
kubectl port-forward service/postgres 5432:5432 -n production
202+
203+
# MySQL
204+
kubectl port-forward service/mysql 3306:3306 -n production
205+
206+
# SQL Server
207+
kubectl port-forward service/mssql 1433:1433 -n production
208+
```
209+
210+
**Step 2: Use the CLI with the connection string**
211+
212+
```bash
213+
# PostgreSQL example
214+
dapr workflow list \
215+
--kubernetes \
216+
--namespace production \
217+
--app-id orderprocessing \
218+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
219+
--table-name workflows
220+
221+
# Purge old workflows
222+
dapr workflow purge \
223+
--kubernetes \
224+
--namespace production \
225+
--app-id orderprocessing \
226+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
227+
--table-name workflows \
228+
--all-older-than 2160h # 90 days
229+
```
230+
231+
**Step 3: Stop port forwarding when done**
232+
233+
```bash
234+
# Press Ctrl+C to stop the port forward
235+
```
236+
237+
#### Connection String Formats by Database
238+
239+
**PostgreSQL / CockroachDB**
240+
```
241+
host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable connect_timeout=10
242+
```
243+
244+
**MySQL**
245+
```
246+
username:password@tcp(host:port)/database?parseTime=true&loc=UTC
247+
```
248+
249+
**SQL Server**
250+
```
251+
sqlserver://username:password@host:port?database=dbname&encrypt=false
252+
```
253+
254+
**MongoDB**
255+
```
256+
mongodb://username:password@localhost:27017/database
257+
```
258+
259+
**Redis**
260+
```
261+
localhost:6379,password=secret,db=0
262+
```
263+
264+
### Workflow Management Best Practices
265+
266+
1. **Regular Cleanup**: Schedule periodic purge operations for completed workflows
267+
```bash
268+
# Weekly cron job to purge workflows older than 90 days
269+
dapr workflow purge --app-id orderprocessing --all-older-than 2160h
270+
```
271+
272+
2. **Monitor Running Workflows**: Use filtered lists to track long-running instances
273+
```bash
274+
dapr workflow list --app-id orderprocessing --filter-status RUNNING --filter-max-age 24h
275+
```
276+
277+
3. **Use Instance IDs**: Assign meaningful instance IDs for easier tracking
278+
```bash
279+
dapr workflow run OrderWorkflow --app-id orderprocessing --instance-id "order-$(date +%s)"
280+
```
281+
282+
4. **Export for Analysis**: Export workflow data for analysis
283+
```bash
284+
dapr workflow list --app-id orderprocessing --output json > workflows.json
285+
```
286+
287+
{{% /tab %}}
288+
13289
<!--Python-->
14290
{{% tab "Python" %}}
15291

daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-architecture.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,34 @@ This number may be larger or smaller depending on retries or concurrency.
189189
| Raise event | 3 records |
190190
| Start child workflow | 8 records |
191191

192+
#### Direct Database Access
193+
194+
For advanced operations, you can access workflow data directly:
195+
196+
```bash
197+
# Port forward to database in Kubernetes
198+
kubectl port-forward service/postgres 5432:5432
199+
200+
# Query workflows directly
201+
dapr workflow list \
202+
--app-id myapp \
203+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
204+
--table-name workflows
205+
```
206+
207+
### Supported State Stores
208+
209+
The workflow engine supports these state stores:
210+
- PostgreSQL
211+
- MySQL
212+
- SQL Server
213+
- SQLite
214+
- Oracle Database
215+
- CockroachDB
216+
- MongoDB
217+
- Redis
218+
219+
192220
## Workflow scalability
193221

194222
Because Dapr Workflows are internally implemented using actors, Dapr Workflows have the same scalability characteristics as actors.

0 commit comments

Comments
 (0)