1- // Package dbos provides a Go SDK for building durable applications with DBOS Transact.
2- //
3- // DBOS Transact enables developers to write resilient distributed applications using workflows
4- // and steps backed by PostgreSQL. All application state is automatically persisted, providing
5- // exactly-once execution guarantees and automatic recovery from failures.
61package dbos
72
83import (
@@ -44,7 +39,6 @@ type Config struct {
4439 Context context.Context // User Context
4540}
4641
47- // processConfig enforces mandatory fields and applies defaults.
4842func processConfig (inputConfig * Config ) (* Config , error ) {
4943 // First check required fields
5044 if len (inputConfig .DatabaseURL ) == 0 {
@@ -103,8 +97,8 @@ type DBOSContext interface {
10397 context.Context
10498
10599 // Context Lifecycle
106- Launch () error // Launch the DBOS runtime including system database, queues, admin server, and workflow recovery
107- Shutdown (timeout time.Duration ) // Gracefully shutdown all DBOS runtime components with ordered cleanup sequence
100+ Launch () error // Launch the DBOS runtime including system database, queues, and perform a workflow recovery for the local executor
101+ Shutdown (timeout time.Duration ) // Gracefully shutdown all DBOS resources
108102
109103 // Workflow operations
110104 RunAsStep (_ DBOSContext , fn StepFunc , opts ... StepOption ) (any , error ) // Execute a function as a durable step within a workflow
@@ -167,7 +161,6 @@ type dbosContext struct {
167161 logger * slog.Logger
168162}
169163
170- // Implement contex.Context interface methods
171164func (c * dbosContext ) Deadline () (deadline time.Time , ok bool ) {
172165 return c .ctx .Deadline ()
173166}
@@ -209,7 +202,7 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
209202}
210203
211204// WithoutCancel returns a copy of the DBOS context that is not canceled when the parent context is canceled.
212- // This is useful for operations that should continue even after a workflow is cancelled .
205+ // This can be used to detach a child workflow .
213206// No-op if the provided context is not a concrete dbos.dbosContext.
214207func WithoutCancel (ctx DBOSContext ) DBOSContext {
215208 if ctx == nil {
@@ -275,17 +268,16 @@ func (c *dbosContext) GetApplicationID() string {
275268}
276269
277270// NewDBOSContext creates a new DBOS context with the provided configuration.
278- // The context must be launched with Launch() before use and should be shut down with Shutdown().
279- // This function initializes the DBOS system database, sets up the queue sub-system,
280- // and prepares the workflow registry.
271+ // The context must be launched with Launch() for workflow execution and should be shut down with Shutdown().
272+ // This function initializes the DBOS system database, sets up the queue sub-system, and prepares the workflow registry.
281273//
282274// Example:
283275//
284276// config := dbos.Config{
285277// DatabaseURL: "postgres://user:pass@localhost:5432/dbname",
286278// AppName: "my-app",
287279// }
288- // ctx, err := dbos.NewDBOSContext(config)
280+ // ctx, err := dbos.NewDBOSContext(context.Background(), config)
289281// if err != nil {
290282// log.Fatal(err)
291283// }
@@ -355,7 +347,7 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error
355347 apiKey : config .ConductorAPIKey ,
356348 appName : config .AppName ,
357349 }
358- conductor , err := NewConductor (initExecutor , conductorConfig )
350+ conductor , err := newConductor (initExecutor , conductorConfig )
359351 if err != nil {
360352 return nil , newInitializationError (fmt .Sprintf ("failed to initialize conductor: %v" , err ))
361353 }
@@ -367,9 +359,8 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error
367359}
368360
369361// Launch initializes and starts the DBOS runtime components including the system database,
370- // admin server (if configured), queue runner, workflow scheduler, and performs recovery
371- // of any pending workflows on this executor. This method must be called before using the DBOS context
372- // for workflow execution and should only be called once.
362+ // admin server (if enabled), queue runner, workflow scheduler, and performs recovery
363+ // of any pending workflows on this executor.
373364//
374365// Returns an error if the context is already launched or if any component fails to start.
375366func (c * dbosContext ) Launch () error {
@@ -380,7 +371,7 @@ func (c *dbosContext) Launch() error {
380371 // Start the system database
381372 c .systemDB .launch (c )
382373
383- // Start the admin server if configured
374+ // Start the admin server if enabled
384375 if c .config .AdminServer {
385376 adminServer := newAdminServer (c , c .config .AdminServerPort )
386377 err := adminServer .Start ()
@@ -407,7 +398,7 @@ func (c *dbosContext) Launch() error {
407398
408399 // Start the conductor if it has been initialized
409400 if c .conductor != nil {
410- c .conductor .Launch ()
401+ c .conductor .launch ()
411402 c .logger .Debug ("Conductor started" )
412403 }
413404
@@ -459,7 +450,6 @@ func (c *dbosContext) Shutdown(timeout time.Duration) {
459450 case <- done :
460451 c .logger .Debug ("All workflows completed" )
461452 case <- time .After (timeout ):
462- // For now just log a warning: eventually we might want Cancel to return an error.
463453 c .logger .Warn ("Timeout waiting for workflows to complete" , "timeout" , timeout )
464454 }
465455
@@ -491,7 +481,7 @@ func (c *dbosContext) Shutdown(timeout time.Duration) {
491481 // Shutdown the conductor
492482 if c .conductor != nil {
493483 c .logger .Debug ("Shutting down conductor" )
494- c .conductor .Shutdown (timeout )
484+ c .conductor .shutdown (timeout )
495485 }
496486
497487 // Shutdown the admin server
0 commit comments