Skip to content

Commit f9c0b2e

Browse files
authored
Document Introspection (#346)
Document all programmatic workflow introspection methods. Give workflow management its own top-level page.
1 parent 7390120 commit f9c0b2e

File tree

8 files changed

+208
-188
lines changed

8 files changed

+208
-188
lines changed

docs/production/dbos-cloud/cloud-cli.md

+5-31
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ This command retrieves the status of a Postgres database instance
107107
This command resets your password for a Postgres database instance.
108108

109109
**Arguments:**
110-
- `[database-instance-name]`: The name of the database instance to provision.
110+
- `[database-instance-name]`: The name of the database instance whose password to reset.
111111
- `-W, --password [string]`: Your new password for this database instance. If not provided, will be prompted on the command line. Passwords must contain 8 or more characters.
112112

113113
---
@@ -122,43 +122,18 @@ This command destroys a previously-provisioned Postgres database instance.
122122

123123
---
124124

125-
### `dbos-cloud db local`
125+
### `dbos-cloud db url`
126126

127127
**Description:**
128-
Configure `dbos-config.yaml` to use a DBOS Cloud Postgres server for local development.
129-
This command also sets the `local_suffix` field in `dbos-config.yaml`, so your application will suffix its application database name with `_local` while running locally.
130-
This isolates the database you use for local development from the database used by your app deployed to DBOS Cloud even though both use the same Postgres server.
131-
132-
133-
**Arguments:**
134-
- `[database-instance-name]`: The name of the database instance to which to connect.
135-
- `-W, --password [string]`: Your password for this database instance. If not provided, will be prompted on the command line.
136-
137-
---
138-
139-
### `dbos-cloud db connect`
140-
141-
**Description:**
142-
This command loads your cloud database's connection parameters into your local `dbos-config.yaml`.
128+
This command retrives your cloud database connection URL.
143129

144130
**Arguments:**
145131
- `[database-instance-name]`: The name of the database instance to which to connect.
132+
- `-S, --show-password`: Whether to show your database password in the output.
146133
- `-W, --password [string]`: Your password for this database instance. If not provided, will be prompted on the command line.
147134

148135
---
149136

150-
### `dbos-cloud db restore`
151-
152-
**Description:**
153-
This command performs [PostgreSQL point-in-time-recovery](https://www.postgresql.org/docs/current/continuous-archiving.html) to create a new database instance containing the state of your database instance at a previous point in time.
154-
After restoration is complete, we recommend using [`change-database-instance`](#dbos-cloud-app-change-database-instance) to redeploy your applications to the new database instance, then [destroying](#dbos-cloud-db-destroy) the original.
155-
156-
**Arguments:**
157-
- `<database-instance-name>`: The name of the database instance to restore from.
158-
- `-t, --restore-time <string>`: The timestamp to restore from, in [RFC3339 format](https://datatracker.ietf.org/doc/html/rfc3339). Must be within the backup retention period of your database (24 hours for free-tier users).
159-
- `-n, --target-name <string>`: The name of the new database instance to create.
160-
---
161-
162137
### `dbos-cloud db link`
163138

164139
**Description:**
@@ -312,12 +287,11 @@ It retrieves an application's logs.
312287
**Description:**
313288
This command must be run from an application root directory.
314289
It redeploys the application to a new database instance.
315-
It is meant to be used with [`database restore`](#dbos-cloud-db-restore) during disaster recovery to transfer the application to the restored database instance.
316290

317291
**Arguments:**
318292
- `--verbose`: Logs debug information about the deployment process, including config file processing and files sent.
319293
- `-d, --database <string>` The name of the new database instance for this application.
320-
- `-p, --previous-version [number]`: The ID of a previous version of this application. If this is supplied, redeploy that version instead of deploying from the application directory. During restoration, we recommend deploying to the version active at the timestamp to which you recovered. You can list previous versions and their IDs and timestamps with the [versions command](#dbos-cloud-app-versions).
294+
- `-p, --previous-version [number]`: The ID of a previous version of this application. If this is supplied, redeploy that version instead of deploying from the application directory.
321295

322296
---
323297

docs/production/dbos-cloud/database-management.md

-36
Original file line numberDiff line numberDiff line change
@@ -65,42 +65,6 @@ While it is occasionally necessary, be careful when manually changing the schema
6565
Be careful making breaking schema changes such as deleting or renaming a column&#8212;they may break active workflows running on a previous application version.
6666
:::
6767

68-
### Database Recovery
69-
70-
:::info
71-
Database recovery is not available for [linked databases](./byod-management.md)
72-
:::
73-
74-
DBOS Cloud can use [PostgreSQL point-in-time-recovery](https://www.postgresql.org/docs/current/continuous-archiving.html) to restore your database to a previous state, for example to recover from data corruption or loss.
75-
First, run the [`database restore`](./cloud-cli.md#dbos-cloud-db-restore) to create a new database instance containing the state of your database instance at a previous point in time:
76-
77-
```shell
78-
dbos-cloud db restore <database-name> -t <timestamp> -n <new-db-instance-name>
79-
```
80-
81-
The timestamp must be in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339) format and must be within the backup retention period of your database (24 hours for free-tier users).
82-
83-
After the database is restored, you can redeploy your applications to it with [`app change-database-instance`](./cloud-cli.md#dbos-cloud-app-change-database-instance).
84-
For each application connected to the original database instance, run:
85-
86-
```shell
87-
dbos-cloud app change-database-instance --database <new-db-instance-name>
88-
```
89-
90-
If you wish to restore your application to a previous version (such as the version that was running at the recovery timestamp), you can do this with the `--previous-version` parameter:
91-
92-
```shell
93-
dbos-cloud app change-database-instance --database <new-db-instance-name> --previous-version <version-id>
94-
```
95-
96-
For more information on application version management, see [here](./application-management.md#managing-application-versions).
97-
98-
Finally, destroy the original database instance:
99-
100-
```shell
101-
dbos-cloud db destroy <original-database-instance-name>
102-
```
103-
10468
### Destroying Database Instances
10569

10670
To destroy a database instance, run:

docs/python/reference/contexts.md

+158-16
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,140 @@ async def example_workflow(var1: str, var2: str):
229229
handle: WorkflowHandleAsync = await DBOS.start_workflow_async(example_workflow, "var1", "var2")
230230
```
231231

232+
## Workflow Management Methods
233+
234+
### list_workflows
235+
```python
236+
def list_workflows(
237+
*,
238+
workflow_ids: Optional[List[str]] = None,
239+
status: Optional[str] = None,
240+
start_time: Optional[str] = None,
241+
end_time: Optional[str] = None,
242+
name: Optional[str] = None,
243+
app_version: Optional[str] = None,
244+
user: Optional[str] = None,
245+
limit: Optional[int] = None,
246+
offset: Optional[int] = None,
247+
sort_desc: bool = False,
248+
) -> List[WorkflowStatus]:
249+
```
250+
251+
Retrieve a list of [`WorkflowStatus`](#workflow-status) of all workflows matching specified criteria.
252+
253+
**Parameters:**
254+
- **workflow_ids**: Retrieve workflows with these IDs.
255+
- **status**: Retrieve workflows with this status (Must be `ENQUEUED`, `PENDING`, `SUCCESS`, `ERROR`, `CANCELLED`, or `RETRIES_EXCEEDED`)
256+
- **start_time**: Retrieve workflows started after this (RFC 3339-compliant) timestamp.
257+
- **end_time**: Retrieve workflows started before this (RFC 3339-compliant) timestamp.
258+
- **name**: Retrieve workflows with this fully-qualified name.
259+
- **app_version**: Retrieve workflows tagged with this application version.
260+
- **user**: Retrieve workflows run by this authenticated user.
261+
- **limit**: Retrieve up to this many workflows.
262+
- **offset**: Skip this many workflows from the results returned (for pagination).
263+
- **sort_desc**: Whether to sort the results in descending (`True`) or ascending (`False`) order by workflow start time.
264+
265+
### list_queued_workflows
266+
```python
267+
def list_queued_workflows(
268+
*,
269+
queue_name: Optional[str] = None,
270+
status: Optional[str] = None,
271+
start_time: Optional[str] = None,
272+
end_time: Optional[str] = None,
273+
name: Optional[str] = None,
274+
limit: Optional[int] = None,
275+
offset: Optional[int] = None,
276+
sort_desc: bool = False,
277+
) -> List[WorkflowStatus]:
278+
```
279+
280+
Retrieve a list of [`WorkflowStatus`](#workflow-status) of all **currently enqueued** workflows matching specified criteria.
281+
282+
**Parameters:**
283+
- **queue_name**: Retrieve workflows running on this queue.
284+
- **status**: Retrieve workflows with this status (Must be `ENQUEUED` or `PENDING`)
285+
- **start_time**: Retrieve workflows enqueued after this (RFC 3339-compliant) timestamp.
286+
- **end_time**: Retrieve workflows enqueued before this (RFC 3339-compliant) timestamp.
287+
- **name**: Retrieve workflows with this fully-qualified name.
288+
- **limit**: Retrieve up to this many workflows.
289+
- **offset**: Skip this many workflows from the results returned (for pagination).
290+
291+
### cancel_workflow
292+
293+
```python
294+
DBOS.cancel_workflow(
295+
workflow_id: str,
296+
) -> None
297+
```
298+
299+
Cancel a workflow.
300+
This sets is status to `CANCELLED`, removes it from its queue (if it is enqueued) and preempts its execution (interrupting it at the beginning of its next step)
301+
302+
### resume_workflow
303+
304+
```python
305+
DBOS.resume_workflow(
306+
workflow_id: str,
307+
) -> WorkflowHandle[R]
308+
```
309+
310+
Resume a workflow.
311+
This immediately starts it from its last completed step.
312+
You can use this to resume workflows that are cancelled or have exceeded their maximum recovery attempts.
313+
You can also use this to start an enqueued workflow immediately, bypassing its queue.
314+
315+
### restart_workflow
316+
317+
```python
318+
DBOS.restart_workflow(
319+
workflow_id: str,
320+
) -> WorkflowHandle[R]
321+
```
322+
323+
Start a new execution of a workflow with the same inputs as the original, but a new workflow ID.
324+
325+
### Workflow Status
326+
327+
Some workflow introspection and management methods return a `WorkflowStatus`.
328+
This object has the following definition:
329+
330+
```python
331+
class WorkflowStatus:
332+
# The workflow ID
333+
workflow_id: str
334+
# The workflow status. Must be one of ENQUEUED, PENDING, SUCCESS, ERROR, CANCELLED, or RETRIES_EXCEEDED
335+
status: str
336+
# The name of the workflow function
337+
name: str
338+
# The name of the workflow's class, if any
339+
class_name: Optional[str]
340+
# The name with which the workflow's class instance was configured, if any
341+
config_name: Optional[str]
342+
# The user who ran the workflow, if specified
343+
authenticated_user: Optional[str]
344+
# The role with which the workflow ran, if specified
345+
assumed_role: Optional[str]
346+
# All roles which the authenticated user could assume
347+
authenticated_roles: Optional[list[str]]
348+
# The deserialized workflow input object
349+
input: Optional[WorkflowInputs]
350+
# The workflow's output, if any
351+
output: Optional[Any]
352+
# The error the workflow threw, if any
353+
error: Optional[Exception]
354+
# Workflow start time, as a Unix epoch timestamp in ms
355+
created_at: Optional[int]
356+
# Last time the workflow status was updated, as a Unix epoch timestamp in ms
357+
updated_at: Optional[int]
358+
# If this workflow was enqueued, on which queue
359+
queue_name: Optional[str]
360+
# The executor to most recently executed this workflow
361+
executor_id: Optional[str]
362+
# The application version on which this workflow was started
363+
app_version: Optional[str]
364+
```
365+
232366
## Context Variables
233367

234368
### logger
@@ -262,34 +396,42 @@ DBOS.workflow_id: str
262396
May only be accessed from within a workflow, step, or transaction.
263397
Return the identity of the current workflow.
264398

265-
### span
399+
### step_id
266400

267401
```python
268-
DBOS.span: opentelemetry.trace.Span
402+
DBOS.step_id: int
269403
```
270404

271-
Retrieve the OpenTelemetry span associated with the curent request.
272-
You can use this to set custom attributes in your span.
405+
Returns the unique ID of the current step within a workflow.
273406

274-
### request
407+
### step_status
275408

276409
```python
277-
DBOS.request: Request
410+
DBOS.step_status: StepStatus
278411
```
279412

280-
May only be accessed from within the handler of a FastAPI request, or in a function called from the handler.
281-
Retrieve request information parsed from FastAPI:
413+
Return the status of the currently executing step.
414+
This object has the following properties:
415+
282416
```python
283-
headers: Headers # The request headers
284-
path_params: dict[str, Any] # The request's path parameters
285-
query_params QueryParams # The request's query parameters
286-
url: URL # The URL to which the request was sent
287-
base_url: URL # The base URL of the request
288-
client: Optional[Address] # Information about the client that sent the request
289-
cookies: dict[str, str] # The request's cookie parameters
290-
method: str # The HTTP method of the request
417+
class StepStatus:
418+
# The unique ID of this step in its workflow.
419+
step_id: int
420+
# For steps with automatic retries, which attempt number (zero-indexed) is currently executing.
421+
current_attempt: Optional[int]
422+
# For steps with automatic retries, the maximum number of attempts that will be made before the step fails.
423+
max_attempts: Optional[int]
291424
```
292425

426+
### span
427+
428+
```python
429+
DBOS.span: opentelemetry.trace.Span
430+
```
431+
432+
Retrieve the OpenTelemetry span associated with the curent request.
433+
You can use this to set custom attributes in your span.
434+
293435
### config
294436

295437
```python

docs/python/reference/workflow_handles.md

+2-16
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Wait for the workflow to complete, then return its result.
3434
handle.get_status() -> WorkflowStatus
3535
```
3636

37-
Retrieve the [workflow's status](#workflowstatus), defined below.
37+
Retrieve the [`WorkflowStatus`](./contexts.md#workflow-status) of a workflow.
3838

3939

4040
## WorkflowHandleAsync
@@ -63,18 +63,4 @@ Asynchronously wait for the workflow to complete, then return its result. Simila
6363
handle.get_status() -> Coroutine[Any, Any, WorkflowStatus]
6464
```
6565

66-
Asynchronously retrieves the [workflow's status](#workflowstatus), defined below.
67-
68-
## WorkflowStatus
69-
70-
```python
71-
class WorkflowStatus:
72-
workflow_id: str # The workflow's ID
73-
status: str # The workflow's current state. One of PENDING, SUCCESS, ERROR, RETRIES_EXCEEDED, or CANCELLED
74-
name: str # The fully qualified name of the workflow function
75-
class_name: Optional[str] # If the workflow function is a class method, the name of the class
76-
config_name: Optional[str] # If the workflow function is a method of a configured class, the name of the class configuration
77-
authenticated_user: Optional[str] # The authenticated user running the workflow
78-
assumed_role: Optional[str] # The role with which the workflow is run
79-
authenticatedRoles: Optional[List[str]] # All roles which the authenticated user could assume
80-
```
66+
Asynchronously retrieve the [`WorkflowStatus`](./contexts.md#workflow-status) of a workflow.

docs/python/tutorials/queue-tutorial.md

-38
Original file line numberDiff line numberDiff line change
@@ -139,41 +139,3 @@ def process_event(event: str):
139139
def event_endpoint(event: str):
140140
queue.enqueue(process_event, event)
141141
```
142-
143-
144-
### Queue Management
145-
146-
Because DBOS manages queues in Postgres, you can view and manage queued functions from the command line.
147-
These commands are also available for applications deployed to DBOS Cloud using the [cloud CLI](../../production/dbos-cloud/cloud-cli.md).
148-
149-
#### Listing Queued Functions
150-
151-
You can list all currently enqueued functions with:
152-
153-
```shell
154-
dbos workflow list
155-
```
156-
157-
By default, this lists all currently enqueued functions, including queued functions that are currently executing, but not completed functions
158-
You can parameterize this command for advanced search, see full documentation [here](../reference/cli.md#dbos-workflow-queue-list).
159-
160-
#### Removing Queued Functions
161-
162-
You can remove a function from a queue with:
163-
164-
```shell
165-
dbos workflow cancel <workflow-id>
166-
```
167-
168-
This removes the function from its queue and transitions it to a `CANCELLED` state, so it will not run unless manually resumed.
169-
170-
#### Resuming Workflows
171-
172-
You can start execution of an enqueued function with:
173-
174-
```shell
175-
dbos workflow resume <workflow-id>
176-
```
177-
178-
This starts execution immediately, bypassing the queue and transitioning the function to a `PENDING` state.
179-
It also removes the function from its queue.

0 commit comments

Comments
 (0)