Skip to content

Commit a0e1419

Browse files
committed
Dedicated ClientConfig for the DBOS Client
1 parent 789269d commit a0e1419

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

dbos/client.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import (
55
"encoding/gob"
66
"errors"
77
"fmt"
8+
"log/slog"
89
"math"
910
"time"
1011

1112
"github.com/google/uuid"
13+
"github.com/jackc/pgx/v5/pgxpool"
1214
)
1315

16+
type ClientConfig struct {
17+
DatabaseURL string // Connection URL for the PostgreSQL database
18+
Logger *slog.Logger // Optional custom logger
19+
SystemDBPool *pgxpool.Pool // Optional existing connection pool for the system database
20+
}
21+
1422
// Client provides a programmatic way to interact with your DBOS application from external code.
1523
// It manages the underlying DBOSContext and provides methods for workflow operations
1624
// without requiring direct management of the context lifecycle.
@@ -35,16 +43,20 @@ type client struct {
3543
//
3644
// Example:
3745
//
38-
// config := dbos.Config{
46+
// config := dbos.ClientConfig{
3947
// DatabaseURL: "postgres://user:pass@localhost:5432/dbname",
40-
// AppName: "my-app",
4148
// }
4249
// client, err := dbos.NewClient(context.Background(), config)
4350
// if err != nil {
4451
// log.Fatal(err)
4552
// }
46-
func NewClient(ctx context.Context, config Config) (Client, error) {
47-
dbosCtx, err := NewDBOSContext(ctx, config)
53+
func NewClient(ctx context.Context, config ClientConfig) (Client, error) {
54+
dbosCtx, err := NewDBOSContext(ctx, Config{
55+
DatabaseURL: config.DatabaseURL,
56+
AppName: "dbos-client",
57+
Logger: config.Logger,
58+
SystemDBPool: config.SystemDBPool,
59+
})
4860
if err != nil {
4961
return nil, err
5062
}

dbos/client_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ func TestEnqueue(t *testing.T) {
6565

6666
// Setup client - this will enqueue tasks
6767
databaseURL := getDatabaseURL()
68-
config := Config{
68+
config := ClientConfig{
6969
DatabaseURL: databaseURL,
70-
AppName: "test-app",
7170
}
7271
client, err := NewClient(context.Background(), config)
7372
require.NoError(t, err)
@@ -325,9 +324,8 @@ func TestCancelResume(t *testing.T) {
325324

326325
// Setup client - this will enqueue tasks
327326
databaseURL := getDatabaseURL()
328-
config := Config{
327+
config := ClientConfig{
329328
DatabaseURL: databaseURL,
330-
AppName: "test-app",
331329
}
332330
client, err := NewClient(context.Background(), config)
333331
require.NoError(t, err)
@@ -577,9 +575,8 @@ func TestForkWorkflow(t *testing.T) {
577575

578576
// Setup client
579577
databaseURL := getDatabaseURL()
580-
config := Config{
578+
config := ClientConfig{
581579
DatabaseURL: databaseURL,
582-
AppName: "test-app",
583580
}
584581
client, err := NewClient(context.Background(), config)
585582
require.NoError(t, err)
@@ -719,9 +716,8 @@ func TestListWorkflows(t *testing.T) {
719716

720717
// Setup client
721718
databaseURL := getDatabaseURL()
722-
config := Config{
719+
config := ClientConfig{
723720
DatabaseURL: databaseURL,
724-
AppName: "test-app",
725721
}
726722
client, err := NewClient(context.Background(), config)
727723
require.NoError(t, err)

0 commit comments

Comments
 (0)