Skip to content

Commit 9a4cb1a

Browse files
committed
docs + nit
1 parent 7ce58ab commit 9a4cb1a

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

dbos/workflow.go

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,61 @@ type GenericEnqueueOptions[P any] struct {
13341334
WorkflowInput P
13351335
}
13361336

1337+
// Enqueue adds a workflow to a named queue for later execution with type safety.
1338+
// The workflow will be persisted with ENQUEUED status until picked up by a DBOS process.
1339+
// This provides asynchronous workflow execution with durability guarantees.
1340+
//
1341+
// Parameters:
1342+
// - ctx: DBOS context for the operation
1343+
// - params: Configuration parameters including workflow name, queue name, input, and options
1344+
//
1345+
// The params struct contains:
1346+
// - WorkflowName: Name of the registered workflow function to execute (required)
1347+
// - QueueName: Name of the queue to enqueue the workflow to (required)
1348+
// - WorkflowID: Custom workflow ID (optional, auto-generated if empty)
1349+
// - ApplicationVersion: Application version override (optional)
1350+
// - DeduplicationID: Deduplication identifier for idempotent enqueuing (optional)
1351+
// - WorkflowTimeout: Maximum execution time for the workflow (optional)
1352+
// - WorkflowInput: Input parameters to pass to the workflow (type P)
1353+
//
1354+
// Returns a typed workflow handle that can be used to check status and retrieve results.
1355+
// The handle uses polling to check workflow completion since the execution is asynchronous.
1356+
//
1357+
// Example usage:
1358+
//
1359+
// // Enqueue a workflow with string input and int output
1360+
// handle, err := dbos.Enqueue[string, int](ctx, dbos.GenericEnqueueOptions[string]{
1361+
// WorkflowName: "ProcessDataWorkflow",
1362+
// QueueName: "data-processing",
1363+
// WorkflowInput: "input data",
1364+
// WorkflowTimeout: 30 * time.Minute,
1365+
// })
1366+
// if err != nil {
1367+
// log.Fatal(err)
1368+
// }
1369+
//
1370+
// // Check status
1371+
// status, err := handle.GetStatus()
1372+
// if err != nil {
1373+
// log.Printf("Failed to get status: %v", err)
1374+
// }
1375+
//
1376+
// // Wait for completion and get result
1377+
// result, err := handle.GetResult() // blocks until completion
1378+
// if err != nil {
1379+
// log.Printf("Workflow failed: %v", err)
1380+
// } else {
1381+
// log.Printf("Result: %d", result)
1382+
// }
1383+
//
1384+
// // Enqueue with deduplication and custom workflow ID
1385+
// handle, err := dbos.Enqueue[MyInputType, MyOutputType](ctx, dbos.GenericEnqueueOptions[MyInputType]{
1386+
// WorkflowName: "MyWorkflow",
1387+
// QueueName: "my-queue",
1388+
// WorkflowID: "custom-workflow-id",
1389+
// DeduplicationID: "unique-operation-id",
1390+
// WorkflowInput: MyInputType{Field: "value"},
1391+
// })
13371392
func Enqueue[P any, R any](ctx DBOSContext, params GenericEnqueueOptions[P]) (WorkflowHandle[R], error) {
13381393
if ctx == nil {
13391394
return nil, errors.New("ctx cannot be nil")
@@ -1363,9 +1418,7 @@ func Enqueue[P any, R any](ctx DBOSContext, params GenericEnqueueOptions[P]) (Wo
13631418
}
13641419

13651420
// CancelWorkflow cancels a running or enqueued workflow by setting its status to CANCELLED.
1366-
// Once cancelled, the workflow will stop executing and cannot be resumed.
1367-
// If the workflow has already completed (SUCCESS or ERROR), this operation has no effect.
1368-
// The workflow's final status and any partial results remain accessible through its handle.
1421+
// Once cancelled, the workflow will stop executing. Currently executing steps will not be interrupted.
13691422
//
13701423
// Parameters:
13711424
// - workflowID: The unique identifier of the workflow to cancel
@@ -1384,7 +1437,7 @@ func (c *dbosContext) ResumeWorkflow(_ DBOSContext, workflowID string) (Workflow
13841437
}
13851438

13861439
// ResumeWorkflow resumes a cancelled workflow by setting its status back to ENQUEUED.
1387-
// The workflow will be picked up by the queue processor and execution will continue
1440+
// The workflow will be picked up by a DBOS queue processor and execution will continue
13881441
// from where it left off. If the workflow is already completed, this is a no-op.
13891442
// Returns a handle that can be used to wait for completion and retrieve results.
13901443
// Returns an error if the workflow does not exist or if the cancellation operation fails.
@@ -1419,7 +1472,6 @@ func ResumeWorkflow[R any](ctx DBOSContext, workflowID string) (WorkflowHandle[R
14191472
}
14201473

14211474
// ForkWorkflowInput holds configuration parameters for forking workflows.
1422-
// It replaces the functional options pattern to comply with CS-5 style guidelines.
14231475
type ForkWorkflowInput struct {
14241476
OriginalWorkflowID string // Required: The UUID of the original workflow to fork from
14251477
ForkedWorkflowID string // Optional: Custom workflow ID for the forked workflow (auto-generated if empty)
@@ -1460,7 +1512,7 @@ func (c *dbosContext) ForkWorkflow(_ DBOSContext, input ForkWorkflowInput) (Work
14601512

14611513
// ForkWorkflow creates a new workflow instance by copying an existing workflow from a specific step.
14621514
// The forked workflow will have a new UUID and will execute from the specified StartStep.
1463-
// If StartStep > 0, the forked workflow will have the operation outputs from steps 0 to StartStep-1
1515+
// If StartStep > 0, the forked workflow will reuse the operation outputs from steps 0 to StartStep-1
14641516
// copied from the original workflow.
14651517
//
14661518
// Parameters:
@@ -1511,7 +1563,7 @@ func ForkWorkflow[R any](ctx DBOSContext, input ForkWorkflowInput) (WorkflowHand
15111563
}
15121564
return &workflowPollingHandle[R]{
15131565
workflowID: handle.GetWorkflowID(),
1514-
dbosContext: handle.(*workflowPollingHandle[any]).dbosContext,
1566+
dbosContext: ctx,
15151567
}, nil
15161568
}
15171569

@@ -1693,8 +1745,6 @@ func WithLoadOutput(loadOutput bool) ListWorkflowsOption {
16931745
}
16941746

16951747
// ListWorkflows retrieves a list of workflows based on the provided filters.
1696-
// This function provides a high-level interface to query workflows with various filtering options.
1697-
// It wraps the system database's listWorkflows functionality with type-safe functional options.
16981748
//
16991749
// The function supports filtering by workflow IDs, status, time ranges, names, application versions,
17001750
// authenticated users, workflow ID prefixes, and more. It also supports pagination through

0 commit comments

Comments
 (0)