Skip to content

Commit e60a507

Browse files
committed
stuff
1 parent e306ad6 commit e60a507

File tree

7 files changed

+82
-45
lines changed

7 files changed

+82
-45
lines changed

docs/golang/reference/dbos-context.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ title: DBOS Context
44
pagination_prev: null
55
---
66

7-
A DBOS Context is at the center of a DBOS-enabled application. Use it to register [workflows](./workflow-tutorial.md), [queues](./queue-tutorial.md) and perform [workflow management](./workflow-management.md) tasks.
7+
A DBOS Context is at the center of a DBOS-enabled application. Use it to register [workflows](../tutorials/workflow-tutorial.md), [queues](../tutorials/queue-tutorial.md) and perform [workflow management](../tutorials/workflow-management.md) tasks.
88

9-
[`DBOSContext`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#DBOSContext) extends Go's [`context.Context`](https://pkg.go.dev/context#Context) interface and carries essential state across workflow execution. Workflows and steps receive a new `DBOSContext` spun out of the root `DBOSContext` you manage. In addition, a `DBOSContext` can be used to set [workflow timeouts](./workflow-tutorial.md#workflow-timeouts).
9+
`DBOSContext` extends Go's [`context.Context`](https://pkg.go.dev/context#Context) interface and carries essential state across workflow execution. Workflows and steps receive a new `DBOSContext` spun out of the root `DBOSContext` you manage. In addition, a `DBOSContext` can be used to set [workflow timeouts](../tutorials/workflow-tutorial.md#workflow-timeouts).
1010

11+
## Lifecycle
1112
### Initialization
1213

13-
You can create a DBOS context using [`NewDBOSContext`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#NewDBOSContext), which takes a [`Config`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#Config) object where `AppName` and `DatabaseURL` are mandatory.
14+
You can create a DBOS context using `NewDBOSContext`, which takes a `Config` object where `AppName` and `DatabaseURL` are mandatory.
1415

1516
```go
1617
func NewDBOSContext(inputConfig Config) (DBOSContext, error)
@@ -49,8 +50,8 @@ DBOSContext.Launch() error
4950

5051
Launch the following resources managed by a `DBOSContext`:
5152
- A [system database connection pool](../../explanations/system-tables.md)
52-
- A [workflow scheduler](./workflow-tutorial.md#scheduled-workflows)
53-
- A [workflow queue runner](./queue-tutorial.md)
53+
- A [workflow scheduler](../tutorials/workflow-tutorial.md#scheduled-workflows)
54+
- A [workflow queue runner](../tutorials/queue-tutorial.md)
5455
- (Optionally) an admin server
5556
- (Optionally) a conductor connection
5657

@@ -66,14 +67,15 @@ Gracefully shutdown the DBOS runtime, waiting for workflows to complete and clea
6667
**Parameters:**
6768
- **timeout**: The time to wait for workflows to complete. After the timeout elapses, execution of incomplete workflows is terminated (the workflows may then be recovered by other processes).
6869

70+
## Context management
6971

7072
### WithTimeout
7173

7274
```go
7375
func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.CancelFunc)
7476
```
7577

76-
WithTimeout returns a copy of the DBOS context with a timeout. The returned context will be canceled after the specified duration. See [workflow timeouts](./workflow-tutorial.md#workflow-timeouts) for usage.
78+
WithTimeout returns a copy of the DBOS context with a timeout. The returned context will be canceled after the specified duration. See [workflow timeouts](../tutorials/workflow-tutorial.md#workflow-timeouts) for usage.
7779

7880
### WithoutCancel
7981

@@ -99,6 +101,7 @@ func GetStepID(ctx DBOSContext) (int, error)
99101

100102
GetStepID retrieves the current step ID from the context if called within a DBOS workflow. Returns -1 and an error if not called from within a workflow context.
101103

104+
## Context metadata
102105
### GetApplicationVersion
103106

104107
```go

docs/golang/reference/methods.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,23 @@ Resume a workflow. This immediately starts it from its last completed step. You
288288
### ForkWorkflow
289289

290290
```go
291-
func ForkWorkflow[R any](ctx DBOSContext, workflowID string, startStep int, opts ...WorkflowOptions) (*WorkflowHandle[R], error)
291+
func ForkWorkflow[R any](ctx DBOSContext, input ForkWorkflowInput) (WorkflowHandle[R], error)
292292
```
293293

294294
Start a new execution of a workflow from a specific step. The input step ID (`startStep`) must match the step number of the step returned by workflow introspection. The specified `startStep` is the step from which the new workflow will start, so any steps whose ID is less than `startStep` will not be re-executed.
295295

296296
**Parameters:**
297297
- **ctx**: The DBOS context.
298-
- **workflowID**: The ID of the workflow to fork.
299-
- **startStep**: The ID of the step from which to start the forked workflow.
300-
- **opts**: Optional workflow configuration options (documented [here](./workflows-steps.md#dbosrunworkflow)).
298+
- **input**: A `ForkWorkflowInput` struct where `OriginalWorkflowID` is mandatory.
299+
300+
```go
301+
type ForkWorkflowInput struct {
302+
OriginalWorkflowID string // Required: The UUID of the original workflow to fork from
303+
ForkedWorkflowID string // Optional: Custom workflow ID for the forked workflow (auto-generated if empty)
304+
StartStep uint // Optional: Step to start the forked workflow from (default: 0)
305+
ApplicationVersion string // Optional: Application version for the forked workflow (inherits from original if empty)
306+
}
307+
```
301308

302309
### Workflow Status
303310

docs/golang/tutorials/queue-tutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ toc_max_heading_level: 3
77
You can use queues to run many workflows at once with managed concurrency.
88
Queues provide _flow control_, letting you manage how many workflows run at once or how often workflows are started.
99

10-
To create a queue, use [`NewWorkflowQueue`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#NewWorkflowQueue)
10+
To create a queue, use [`NewWorkflowQueue`](../reference/queues#newworkflowqueue)
1111

1212
```go
1313
queue := dbos.NewWorkflowQueue(dbosContext, "example_queue")
1414
```
1515

16-
You can then enqueue any workflow using [`WithQueue`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithQueue) when calling `RunWorkflow`.
17-
Enqueuing a function submits it for execution and returns a [handle](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WorkflowHandle) to it.
16+
You can then enqueue any workflow using [`WithQueue`](../reference/workflows-steps#withqueue) when calling `RunWorkflow`.
17+
Enqueuing a function submits it for execution and returns a [handle](../reference/workflows-steps#workflowhandle) to it.
1818
Queued tasks are started in first-in, first-out (FIFO) order.
1919

2020
```go
@@ -144,7 +144,7 @@ Rate limits are especially useful when working with a rate-limited API, such as
144144

145145
### Deduplication
146146

147-
You can set a deduplication ID for an enqueued workflow using [`WithDeduplicationID`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithDeduplicationID) when calling `RunWorkflow`.
147+
You can set a deduplication ID for an enqueued workflow using [`WithDeduplicationID`](../reference/workflows-steps#withdeduplicationid) when calling `RunWorkflow`.
148148
At any given time, only one workflow with a specific deduplication ID can be enqueued in the specified queue.
149149
If a workflow with a deduplication ID is currently enqueued or actively executing (status `ENQUEUED` or `PENDING`), subsequent workflow enqueue attempts with the same deduplication ID in the same queue will return an error.
150150

@@ -183,9 +183,9 @@ func example(dbosContext dbos.DBOSContext, queue dbos.WorkflowQueue) error {
183183

184184
### Priority
185185

186-
You can set a priority for an enqueued workflow using [`WithPriority`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithPriority) when calling `RunWorkflow`.
186+
You can set a priority for an enqueued workflow using [`WithPriority`](../reference/workflows-steps#withpriority) when calling `RunWorkflow`.
187187
Workflows with the same priority are dequeued in **FIFO (first in, first out)** order. Priority values can range from `1` to `2,147,483,647`, where **a low number indicates a higher priority**.
188-
If using priority, you must set [`WithPriorityEnabled`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithPriorityEnabled) on your queue.
188+
If using priority, you must set [`WithPriorityEnabled`](../reference/queues#withpriorityenabled) on your queue.
189189

190190
:::tip
191191
Workflows without assigned priorities have the highest priority and are dequeued before workflows with assigned priorities.

docs/golang/tutorials/step-tutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Steps
66
When using DBOS workflows, you should call any function that performs complex operations or accesses external APIs or services as a _step_.
77
If a workflow is interrupted, upon restart it automatically resumes execution from the **last completed step**.
88

9-
You can use [`RunAsStep`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#RunAsStep) to call a function as a step.
9+
You can use [`RunAsStep`](../reference/workflows-steps#runasstep) to call a function as a step.
1010
For a function to be used as a step, it should return a serializable ([gob-encodable](https://pkg.go.dev/encoding/gob)) value and an error and have this signature:
1111

1212
```go
@@ -50,11 +50,11 @@ This is useful for automatically handling transient failures, like making reques
5050
Retries are configurable through step options that can be passed to `RunAsStep`.
5151

5252
Available retry configuration options include:
53-
- [`WithStepName`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithStepName) - Custom name for the step (default to the [Go runtime reflection value](https://pkg.go.dev/runtime#FuncForPC))
54-
- [`WithStepMaxRetries`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithStepMaxRetries) - Maximum number of times this step is automatically retried on failure (default 0)
55-
- [`WithMaxInterval`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithMaxInterval) - Maximum delay between retries (default 5s)
56-
- [`WithBackoffFactor`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithBackoffFactor) - Exponential backoff multiplier between retries (default 2.0)
57-
- [`WithBaseInterval`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#WithBaseInterval) - Initial delay between retries (default 100ms)
53+
- [`WithStepName`](../reference/workflows-steps#withstepname) - Custom name for the step (default to the [Go runtime reflection value](https://pkg.go.dev/runtime#FuncForPC))
54+
- [`WithStepMaxRetries`](../reference/workflows-steps#withstepmaxretries) - Maximum number of times this step is automatically retried on failure (default 0)
55+
- [`WithMaxInterval`](../reference/workflows-steps#withmaxinterval) - Maximum delay between retries (default 5s)
56+
- [`WithBackoffFactor`](../reference/workflows-steps#withbackofffactor) - Exponential backoff multiplier between retries (default 2.0)
57+
- [`WithBaseInterval`](../reference/workflows-steps#withbaseinterval) - Initial delay between retries (default 100ms)
5858

5959
For example, let's configure this step to retry failures (such as if `example.com` is temporarily down) up to 10 times:
6060

docs/golang/tutorials/testing.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,40 @@ title: Testing & Mocking
44
---
55

66

7-
[`DBOSContext`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#DBOSContext) is a fully mockable interface, which you manually mock, or can generate mocks using tools like [mockery](https://github.com/vektra/mockery).
7+
[`DBOSContext`](../reference/dbos-context) is a fully mockable interface, which you manually mock, or can generate mocks using tools like [mockery](https://github.com/vektra/mockery).
8+
9+
<details>
10+
<summary>Sample .mockery.yml configuration</summary>
11+
12+
You can use this configuration file to generate mocks by running `mockery`:
13+
14+
```yaml
15+
all: false
16+
dir: './mocks'
17+
filename: '{{.InterfaceName}}_mock.go'
18+
force-file-write: true
19+
formatter: goimports
20+
include-auto-generated: false
21+
log-level: info
22+
structname: 'Mock{{.InterfaceName}}'
23+
pkgname: 'mocks'
24+
recursive: false
25+
require-template-schema-exists: true
26+
template: testify
27+
template-schema: '{{.Template}}.schema.json'
28+
packages:
29+
github.com/dbos-inc/dbos-transact-golang/dbos:
30+
interfaces:
31+
DBOSContext:
32+
WorkflowHandle:
33+
```
34+
35+
</details>
836
937
Here is an example workflow which:
1038
- Calls a step
1139
- Spawns a child workflow
12-
- Calls a workflow management operation, [ListWorkflows](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#ListWorkflows)
40+
- Calls a workflow management operation, [ListWorkflows](../reference/methods#listworkflows)
1341
1442
1543
```go
@@ -89,13 +117,14 @@ func workflow(ctx dbos.DBOSContext, i int) ([]dbos.WorkflowStatus, error) {
89117
}
90118

91119
func TestMocks(t *testing.T) {
120+
// Create a mock DBOSContext
92121
mockCtx := mocks.NewMockDBOSContext(t)
93122

94123
// Step
95124
mockCtx.On("RunAsStep", mockCtx, mock.Anything, mock.Anything).Return(1, nil)
96125

97126
// Child workflow
98-
mockChildHandle := mocks.NewMockWorkflowHandle[any](t)
127+
mockChildHandle := mocks.NewMockWorkflowHandle[any](t) // mock WorkflowHandle
99128
mockCtx.On("RunWorkflow", mockCtx, mock.Anything, 2, mock.Anything).Return(mockChildHandle, nil).Once()
100129
mockChildHandle.On("GetResult").Return(1, nil)
101130

docs/golang/tutorials/workflow-management.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can view and manage your durable workflow executions via a web UI ([self-hos
77

88
## Listing Workflows
99

10-
You can list your application's workflows programmatically via [`ListWorkflows`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#ListWorkflows).
10+
You can list your application's workflows programmatically via [`ListWorkflows`](../reference/methods#listworkflows).
1111

1212
You can also view a searchable and expandable list of your application's workflows from its page on the DBOS Console (either [self-hosted](../../production/self-hosting/workflow-management.md) or on [DBOS Cloud](../../production/dbos-cloud/workflow-management.md)).
1313

@@ -22,14 +22,14 @@ For example, here is the graph of a workflow that processes multiple tasks concu
2222

2323
## Cancelling Workflows
2424

25-
You can cancel the execution of a workflow from the web UI or programmatically via [`CancelWorkflow`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#CancelWorkflow).
25+
You can cancel the execution of a workflow from the web UI or programmatically via [`CancelWorkflow`](../reference/methods#cancelworkflow).
2626

2727
If the workflow is currently executing, cancelling it preempts its execution (interrupting it at the beginning of its next step).
2828
If the workflow is enqueued, cancelling removes it from the queue.
2929

3030
## Resuming Workflows
3131

32-
You can resume a workflow from its last completed step from the web UI or programmatically via [`ResumeWorkflow`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#ResumeWorkflow).
32+
You can resume a workflow from its last completed step from the web UI or programmatically via [`ResumeWorkflow`](../reference/methods#resumeworkflow).
3333

3434
You can use this to resume workflows that are cancelled or that have exceeded their maximum recovery attempts.
3535
You can also use this to start an enqueued workflow immediately, bypassing its queue.
@@ -41,7 +41,7 @@ When you fork a workflow, DBOS generates a new workflow with a new workflow ID,
4141

4242
Forking a workflow is useful for recovering from outages in downstream services (by forking from the step that failed after the outage is resolved) or for "patching" workflows that failed due to a bug in a previous application version (by forking from the bugged step to an appliation version on which the bug is fixed).
4343

44-
You can fork a workflow programmatically using [`ForkWorkflow`](https://pkg.go.dev/github.com/dbos-inc/dbos-transact-golang/dbos#ForkWorkflow).
44+
You can fork a workflow programmatically using [`ForkWorkflow`](../reference/methods#forkworkflow).
4545
You can also fork a workflow from a step from the web UI by clicking on that step in the workflow's graph visualization:
4646

4747
<img src={require('@site/static/img/workflow-management/workflow-fork.png').default} alt="Workflow List" width="800" className="custom-img"/>

0 commit comments

Comments
 (0)