Skip to content

Commit a6014dc

Browse files
authored
$ dapr workflow CLI docs (#4916)
* Adds dapr workflow docs Based on dapr/cli#1560 Signed-off-by: joshvanl <me@joshvanl.dev> * Remove link references in CLI table Signed-off-by: joshvanl <me@joshvanl.dev> * Fix dapr workflow CLI reference doc Signed-off-by: joshvanl <me@joshvanl.dev> * Update docs for workflow docs Signed-off-by: joshvanl <me@joshvanl.dev> * Add redis example format Signed-off-by: joshvanl <me@joshvanl.dev> * Fix commands on quickstart Signed-off-by: joshvanl <me@joshvanl.dev> * Adds review comments Signed-off-by: joshvanl <me@joshvanl.dev> * Update important purge note Signed-off-by: joshvanl <me@joshvanl.dev> * Make clear about workflow client connection for purging Signed-off-by: joshvanl <me@joshvanl.dev> --------- Signed-off-by: joshvanl <me@joshvanl.dev>
1 parent fc7f51d commit a6014dc

File tree

8 files changed

+1122
-139
lines changed

8 files changed

+1122
-139
lines changed

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

Lines changed: 327 additions & 137 deletions
Large diffs are not rendered by default.

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

Lines changed: 291 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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

@@ -69,6 +69,296 @@ dapr scheduler import -f workflow-reminders-backup.bin
6969
- Create workflow reminders via the Workflow API.
7070
- Manage reminders (list, get, delete, backup/restore) with the dapr scheduler CLI.
7171

72+
## Managing Workflows with the Dapr CLI
73+
74+
The Dapr CLI provides commands for managing workflow instances in both self-hosted and Kubernetes environments.
75+
76+
### Prerequisites
77+
78+
- Dapr CLI version 1.16.2 or later
79+
- A running Dapr application that has registered a workflow
80+
- For database operations: network access to your actor state store
81+
82+
### Basic Workflow Operations
83+
84+
#### Start a Workflow
85+
86+
```bash
87+
# Using the `orderprocessing` application, start a new workflow instance with input data
88+
dapr workflow run OrderProcessingWorkflow \
89+
--app-id orderprocessing \
90+
--input '{"orderId": "12345", "amount": 100.50}'
91+
92+
# Start with a new workflow with a specific instance ID
93+
dapr workflow run OrderProcessingWorkflow \
94+
--app-id orderprocessing \
95+
--instance-id order-12345 \
96+
--input '{"orderId": "12345"}'
97+
98+
# Schedule a new workflow to start at 10:00:00 AM on December 25, 2024, Coordinated Universal Time (UTC).
99+
dapr workflow run OrderProcessingWorkflow \
100+
--app-id orderprocessing \
101+
--start-time "2024-12-25T10:00:00Z"
102+
```
103+
104+
#### List Workflow Instances
105+
106+
```bash
107+
# List all workflows for an app
108+
dapr workflow list --app-id orderprocessing
109+
110+
# Filter by status
111+
dapr workflow list --app-id orderprocessing --filter-status RUNNING
112+
113+
# Filter by workflow name
114+
dapr workflow list --app-id orderprocessing --filter-name OrderProcessingWorkflow
115+
116+
# Filter by age (workflows started in last 24 hours)
117+
dapr workflow list --app-id orderprocessing --filter-max-age 24h
118+
119+
# Get detailed output
120+
dapr workflow list --app-id orderprocessing --output wide
121+
```
122+
123+
#### View Workflow History
124+
125+
```bash
126+
# Get execution history
127+
dapr workflow history order-12345 --app-id orderprocessing
128+
129+
# Get history in JSON format
130+
dapr workflow history order-12345 --app-id orderprocessing --output json
131+
```
132+
133+
#### Control Workflow Execution
134+
135+
```bash
136+
# Suspend a running workflow
137+
dapr workflow suspend order-12345 \
138+
--app-id orderprocessing \
139+
--reason "Waiting for manual approval"
140+
141+
# Resume a suspended workflow
142+
dapr workflow resume order-12345 \
143+
--app-id orderprocessing \
144+
--reason "Approved by manager"
145+
146+
# Terminate a workflow
147+
dapr workflow terminate order-12345 \
148+
--app-id orderprocessing \
149+
--output '{"reason": "Cancelled by customer"}'
150+
```
151+
152+
#### Raise External Events
153+
154+
```bash
155+
# Raise an event for a waiting workflow
156+
dapr workflow raise-event order-12345/PaymentReceived \
157+
--app-id orderprocessing \
158+
--input '{"paymentId": "pay-67890", "amount": 100.50}'
159+
```
160+
161+
#### Re-run Workflows
162+
163+
```bash
164+
# Re-run from the beginning
165+
dapr workflow rerun order-12345 --app-id orderprocessing
166+
167+
# Re-run from a specific event
168+
dapr workflow rerun order-12345 \
169+
--app-id orderprocessing \
170+
--event-id 5
171+
172+
# Re-run with a new instance ID
173+
dapr workflow rerun order-12345 \
174+
--app-id orderprocessing \
175+
--new-instance-id order-12345-retry
176+
```
177+
178+
#### Purge Completed Workflows
179+
180+
Note that purging a workflow from the CLI will also delete all associated Scheduler reminders.
181+
182+
{{% alert title="Important" color="warning" %}}
183+
It is required that a workflow client is running in the application to perform purge operations.
184+
The workflow client connection is required in order to preserve the workflow state machine integrity and prevent corruption.
185+
Errors like the following suggest that the workflow client is not running:
186+
```
187+
failed to purge orchestration state: rpc error: code = FailedPrecondition desc = failed to purge orchestration state: failed to lookup actor: api error: code = FailedPrecondition desc = did not find address for actor
188+
```
189+
{{% /alert %}}
190+
191+
```bash
192+
# Purge a specific instance
193+
dapr workflow purge order-12345 --app-id orderprocessing
194+
195+
# Purge all completed workflows older than 30 days
196+
dapr workflow purge --app-id orderprocessing --all-older-than 720h
197+
198+
# Purge all terminal workflows (use with caution!)
199+
dapr workflow purge --app-id orderprocessing --all
200+
```
201+
202+
### Kubernetes Operations
203+
204+
All commands support the `-k` flag for Kubernetes deployments:
205+
206+
```bash
207+
# List workflows in Kubernetes
208+
dapr workflow list \
209+
--kubernetes \
210+
--namespace production \
211+
--app-id orderprocessing
212+
213+
# Suspend a workflow in Kubernetes
214+
dapr workflow suspend order-12345 \
215+
--kubernetes \
216+
--namespace production \
217+
--app-id orderprocessing \
218+
--reason "Maintenance window"
219+
```
220+
221+
### Advanced: Direct Database Access
222+
223+
For advanced operations like listing and purging workflows, you can connect directly to the actor state store database. This is useful for:
224+
225+
- Querying workflows across multiple app instances
226+
- Bulk operations on workflow metadata
227+
- Custom filtering beyond what the API provides
228+
229+
#### Self-Hosted Mode
230+
231+
In self-hosted mode, the CLI can automatically discover your state store configuration:
232+
233+
```bash
234+
# The CLI reads your component configuration automatically
235+
dapr workflow list --app-id orderprocessing --connection-string=redis://127.0.0.1:6379
236+
```
237+
238+
To override with a specific connection string:
239+
240+
```bash
241+
# PostgreSQL
242+
dapr workflow list \
243+
--app-id orderprocessing \
244+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
245+
--table-name actor-store
246+
247+
# MySQL
248+
dapr workflow list \
249+
--app-id orderprocessing \
250+
--connection-string "dapr:dapr@tcp(localhost:3306)/dapr?parseTime=true" \
251+
--table-name actor-store
252+
253+
# SQL Server
254+
dapr workflow list \
255+
--app-id orderprocessing \
256+
--connection-string "sqlserver://dapr:Pass@word1@localhost:1433?database=dapr" \
257+
--table-name abc
258+
259+
# Redis
260+
dapr workflow list \
261+
--app-id orderprocessing \
262+
--connection-string=redis://user:mypassword@127.0.0.1:6379 \
263+
```
264+
265+
#### Kubernetes Mode with Port Forwarding
266+
267+
In Kubernetes, you need to establish connectivity to your database:
268+
269+
**Step 1: Port forward to your database service**
270+
271+
```bash
272+
# PostgreSQL
273+
kubectl port-forward service/postgres 5432:5432 -n production
274+
275+
# MySQL
276+
kubectl port-forward service/mysql 3306:3306 -n production
277+
278+
# SQL Server
279+
kubectl port-forward service/mssql 1433:1433 -n production
280+
281+
# Redis
282+
kubectl port-forward service/redis 6379:6379 -n production
283+
```
284+
285+
**Step 2: Use the CLI with the connection string**
286+
287+
```bash
288+
# PostgreSQL example
289+
dapr workflow list \
290+
--kubernetes \
291+
--namespace production \
292+
--app-id orderprocessing \
293+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
294+
--table-name workflows
295+
296+
# Purge old workflows
297+
dapr workflow purge \
298+
--kubernetes \
299+
--namespace production \
300+
--app-id orderprocessing \
301+
--connection-string "host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable" \
302+
--table-name workflows \
303+
--all-older-than 2160h # 90 days
304+
```
305+
306+
**Step 3: Stop port forwarding when done**
307+
308+
```bash
309+
# Press Ctrl+C to stop the port forward
310+
```
311+
312+
#### Connection String Formats by Database
313+
314+
**PostgreSQL / CockroachDB**
315+
```
316+
host=localhost user=dapr password=dapr dbname=dapr port=5432 sslmode=disable connect_timeout=10
317+
```
318+
319+
**MySQL**
320+
```
321+
username:password@tcp(host:port)/database?parseTime=true&loc=UTC
322+
```
323+
324+
**SQL Server**
325+
```
326+
sqlserver://username:password@host:port?database=dbname&encrypt=false
327+
```
328+
329+
**MongoDB**
330+
```
331+
mongodb://username:password@localhost:27017/database
332+
```
333+
334+
**Redis**
335+
```
336+
redis://127.0.0.1:6379
337+
```
338+
339+
### Workflow Management Best Practices
340+
341+
1. **Regular Cleanup**: Schedule periodic purge operations for completed workflows
342+
```bash
343+
# Weekly cron job to purge workflows older than 90 days
344+
dapr workflow purge --app-id orderprocessing --all-older-than 2160h
345+
```
346+
347+
2. **Monitor Running Workflows**: Use filtered lists to track long-running instances
348+
```bash
349+
dapr workflow list --app-id orderprocessing --filter-status RUNNING --filter-max-age 24h
350+
```
351+
352+
3. **Use Instance IDs**: Assign meaningful instance IDs for easier tracking
353+
```bash
354+
dapr workflow run OrderWorkflow --app-id orderprocessing --instance-id "order-$(date +%s)"
355+
```
356+
357+
4. **Export for Analysis**: Export workflow data for analysis
358+
```bash
359+
dapr workflow list --app-id orderprocessing --output json > workflows.json
360+
```
361+
72362
{{% /tab %}}
73363

74364
<!--Python-->

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,45 @@ 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 a postgres 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+
```bash
208+
# Port forward to redis database in Kubernetes
209+
kubectl port-forward service/redis 6379:6379
210+
211+
# Query workflows directly
212+
dapr workflow list \
213+
--app-id myapp \
214+
--connection-string redis://127.0.0.1:6379 \
215+
--table-name workflows
216+
```
217+
218+
### Supported State Stores
219+
220+
The workflow engine supports these state stores:
221+
- PostgreSQL
222+
- MySQL
223+
- SQL Server
224+
- SQLite
225+
- Oracle Database
226+
- CockroachDB
227+
- MongoDB
228+
- Redis
229+
230+
192231
## Workflow scalability
193232

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

0 commit comments

Comments
 (0)