Skip to content
Closed
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
12 changes: 0 additions & 12 deletions dbos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,6 @@ func Enqueue[P any, R any](c Client, queueName, workflowName string, input P, op
return nil, errors.New("client cannot be nil")
}

// Register the input and outputs for gob encoding
var logger *slog.Logger
if cl, ok := c.(*client); ok {
if ctx, ok := cl.dbosCtx.(*dbosContext); ok {
logger = ctx.logger
}
}
var typedInput P
safeGobRegister(typedInput, logger)
var typedOutput R
safeGobRegister(typedOutput, logger)

// Call the interface method with the same signature
handle, err := c.Enqueue(queueName, workflowName, input, opts...)
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions dbos/dbos.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,6 @@ func NewDBOSContext(ctx context.Context, inputConfig Config) (DBOSContext, error
initExecutor.logger = config.Logger
initExecutor.logger.Info("Initializing DBOS context", "app_name", config.AppName, "dbos_version", getDBOSVersion())

// Register types we serialize with gob
var t time.Time
safeGobRegister(t, initExecutor.logger)
var ws []WorkflowStatus
safeGobRegister(ws, initExecutor.logger)
var si []StepInfo
safeGobRegister(si, initExecutor.logger)

// Initialize global variables from processed config (already handles env vars and defaults)
initExecutor.applicationVersion = config.ApplicationVersion
initExecutor.executorID = config.ExecutorID
Expand Down
41 changes: 31 additions & 10 deletions dbos/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@ import (
"encoding/gob"
"fmt"
"log/slog"
"reflect"
"strings"
)

func serialize(data any) (string, error) {
var inputBytes []byte
if data != nil {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
if err := enc.Encode(&data); err != nil {
return "", fmt.Errorf("failed to encode data: %w", err)
}
inputBytes = buf.Bytes()
func isNilValue(data any) bool {
if data == nil {
return true
}
v := reflect.ValueOf(data)
// Check if the value is invalid (zero Value from reflect)
if !v.IsValid() {
return true
}
switch v.Kind() {
case reflect.Pointer, reflect.Slice, reflect.Map, reflect.Interface:
return v.IsNil()
}
return false
}

func serialize(data any, logger *slog.Logger) (string, error) {
// Handle nil and nil-able type cases (pointer, slice, map, chan, func, interface)
if isNilValue(data) {
return base64.StdEncoding.EncodeToString([]byte{}), nil
}

// Lazy registration of the type for gob encoding
safeGobRegister(data, logger)

var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
if err := enc.Encode(&data); err != nil {
return "", fmt.Errorf("failed to encode data: %w", err)
}
return base64.StdEncoding.EncodeToString(inputBytes), nil
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
}

func deserialize(data *string) (any, error) {
Expand Down
Loading
Loading