Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions dbos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import (
"encoding/gob"
"errors"
"fmt"
"log/slog"
"math"
"time"

"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgxpool"
)

type ClientConfig struct {
DatabaseURL string // Connection URL for the PostgreSQL database
Logger *slog.Logger // Optional custom logger
SystemDBPool *pgxpool.Pool // Optional existing connection pool for the system database
}

// Client provides a programmatic way to interact with your DBOS application from external code.
// It manages the underlying DBOSContext and provides methods for workflow operations
// without requiring direct management of the context lifecycle.
Expand All @@ -35,16 +43,20 @@ type client struct {
//
// Example:
//
// config := dbos.Config{
// config := dbos.ClientConfig{
// DatabaseURL: "postgres://user:pass@localhost:5432/dbname",
// AppName: "my-app",
// }
// client, err := dbos.NewClient(context.Background(), config)
// if err != nil {
// log.Fatal(err)
// }
func NewClient(ctx context.Context, config Config) (Client, error) {
dbosCtx, err := NewDBOSContext(ctx, config)
func NewClient(ctx context.Context, config ClientConfig) (Client, error) {
dbosCtx, err := NewDBOSContext(ctx, Config{
DatabaseURL: config.DatabaseURL,
AppName: "dbos-client",
Logger: config.Logger,
SystemDBPool: config.SystemDBPool,
})
if err != nil {
return nil, err
}
Expand Down
12 changes: 4 additions & 8 deletions dbos/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ func TestEnqueue(t *testing.T) {

// Setup client - this will enqueue tasks
databaseURL := getDatabaseURL()
config := Config{
config := ClientConfig{
DatabaseURL: databaseURL,
AppName: "test-app",
}
client, err := NewClient(context.Background(), config)
require.NoError(t, err)
Expand Down Expand Up @@ -325,9 +324,8 @@ func TestCancelResume(t *testing.T) {

// Setup client - this will enqueue tasks
databaseURL := getDatabaseURL()
config := Config{
config := ClientConfig{
DatabaseURL: databaseURL,
AppName: "test-app",
}
client, err := NewClient(context.Background(), config)
require.NoError(t, err)
Expand Down Expand Up @@ -577,9 +575,8 @@ func TestForkWorkflow(t *testing.T) {

// Setup client
databaseURL := getDatabaseURL()
config := Config{
config := ClientConfig{
DatabaseURL: databaseURL,
AppName: "test-app",
}
client, err := NewClient(context.Background(), config)
require.NoError(t, err)
Expand Down Expand Up @@ -719,9 +716,8 @@ func TestListWorkflows(t *testing.T) {

// Setup client
databaseURL := getDatabaseURL()
config := Config{
config := ClientConfig{
DatabaseURL: databaseURL,
AppName: "test-app",
}
client, err := NewClient(context.Background(), config)
require.NoError(t, err)
Expand Down
Loading