Skip to content

Commit 652ad8f

Browse files
committed
simplify
1 parent 48824cb commit 652ad8f

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

dbos/serialization_test.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ func TestWorkflowEncoding(t *testing.T) {
292292
})
293293
}
294294

295-
// UserDefinedEventData is a custom struct declared outside of any workflow
296-
// This struct should never appear in the signature of a function registered as a DBOS workflow
297295
type UserDefinedEventData struct {
298296
ID int `json:"id"`
299297
Name string `json:"name"`
@@ -304,7 +302,6 @@ type UserDefinedEventData struct {
304302
}
305303

306304
func setEventUserDefinedTypeWorkflow(ctx context.Context, input string) (string, error) {
307-
// Create an instance of our user-defined type inside the workflow
308305
eventData := UserDefinedEventData{
309306
ID: 42,
310307
Name: "test-event",
@@ -317,8 +314,6 @@ func setEventUserDefinedTypeWorkflow(ctx context.Context, input string) (string,
317314
},
318315
}
319316

320-
// SetEvent should automatically register this type with gob
321-
// Note the explicit type parameter since compiler cannot infer UserDefinedEventData from string input
322317
err := SetEvent(ctx, WorkflowSetEventInput[UserDefinedEventData]{Key: input, Message: eventData})
323318
if err != nil {
324319
return "", err
@@ -379,19 +374,10 @@ func TestSetEventSerialize(t *testing.T) {
379374
})
380375
}
381376

382-
// UserDefinedSendData is a custom struct for testing Send serialization
383-
type UserDefinedSendData struct {
384-
ID int `json:"id"`
385-
Name string `json:"name"`
386-
Details struct {
387-
Description string `json:"description"`
388-
Tags []string `json:"tags"`
389-
} `json:"details"`
390-
}
391377

392378
func sendUserDefinedTypeWorkflow(ctx context.Context, destinationID string) (string, error) {
393379
// Create an instance of our user-defined type inside the workflow
394-
sendData := UserDefinedSendData{
380+
sendData := UserDefinedEventData{
395381
ID: 42,
396382
Name: "test-send-message",
397383
Details: struct {
@@ -404,8 +390,8 @@ func sendUserDefinedTypeWorkflow(ctx context.Context, destinationID string) (str
404390
}
405391

406392
// Send should automatically register this type with gob
407-
// Note the explicit type parameter since compiler cannot infer UserDefinedSendData from string input
408-
err := Send(ctx, WorkflowSendInput[UserDefinedSendData]{
393+
// Note the explicit type parameter since compiler cannot infer UserDefinedEventData from string input
394+
err := Send(ctx, WorkflowSendInput[UserDefinedEventData]{
409395
DestinationID: destinationID,
410396
Topic: "user-defined-topic",
411397
Message: sendData,
@@ -416,9 +402,9 @@ func sendUserDefinedTypeWorkflow(ctx context.Context, destinationID string) (str
416402
return "user-defined-message-sent", nil
417403
}
418404

419-
func recvUserDefinedTypeWorkflow(ctx context.Context, input string) (UserDefinedSendData, error) {
405+
func recvUserDefinedTypeWorkflow(ctx context.Context, input string) (UserDefinedEventData, error) {
420406
// Receive the user-defined type message
421-
result, err := Recv[UserDefinedSendData](ctx, WorkflowRecvInput{
407+
result, err := Recv[UserDefinedEventData](ctx, WorkflowRecvInput{
422408
Topic: "user-defined-topic",
423409
Timeout: 3 * time.Second,
424410
})

dbos/workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ type WorkflowSendInput[R any] struct {
722722
// Send automatically registers the type of R for gob encoding
723723
func Send[R any](ctx context.Context, input WorkflowSendInput[R]) error {
724724
var typedMessage R
725-
gob.Register(typedMessage) // Register the type for gob encoding
725+
gob.Register(typedMessage)
726726
return dbos.systemDB.Send(ctx, workflowSendInputInternal{
727727
destinationID: input.DestinationID,
728728
message: input.Message,
@@ -762,7 +762,7 @@ type WorkflowSetEventInput[R any] struct {
762762
// SetEvent automatically registers the type of R for gob encoding
763763
func SetEvent[R any](ctx context.Context, input WorkflowSetEventInput[R]) error {
764764
var typedMessage R
765-
gob.Register(typedMessage) // Register the type for gob encoding
765+
gob.Register(typedMessage)
766766
return dbos.systemDB.SetEvent(ctx, workflowSetEventInputInternal{
767767
key: input.Key,
768768
message: input.Message,

0 commit comments

Comments
 (0)