@@ -794,6 +794,7 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
794
794
795
795
// If the afterFunc has started, the workflow was cancelled and the status should be set to cancelled
796
796
if stopFunc != nil && ! stopFunc () {
797
+ c .logger .Info ("Workflow was cancelled. Waiting for cancel function to complete" , "workflow_id" , workflowID )
797
798
// Wait for the cancel function to complete
798
799
// Note this must happen before we write on the outcome channel (and signal the handler's GetResult)
799
800
<- cancelFuncCompleted
@@ -817,7 +818,7 @@ func (c *dbosContext) RunAsWorkflow(_ DBOSContext, fn WorkflowFunc, input any, o
817
818
close (outcomeChan )
818
819
}()
819
820
820
- return newWorkflowHandle [ any ] (uncancellableCtx , workflowID , outcomeChan ), nil
821
+ return newWorkflowHandle (uncancellableCtx , workflowID , outcomeChan ), nil
821
822
}
822
823
823
824
/******************************/
@@ -1082,50 +1083,43 @@ func (c *dbosContext) RunAsStep(_ DBOSContext, fn StepFunc, opts ...StepOption)
1082
1083
/******* WORKFLOW COMMUNICATIONS ********/
1083
1084
/****************************************/
1084
1085
1085
- // GenericWorkflowSendInput defines the parameters for sending a message to another workflow.
1086
- type GenericWorkflowSendInput [P any ] struct {
1087
- DestinationID string // Workflow ID to send the message to
1088
- Message P // Message payload (must be gob-encodable)
1089
- Topic string // Optional topic for message filtering
1090
- }
1091
-
1092
- func (c * dbosContext ) Send (_ DBOSContext , input WorkflowSendInput ) error {
1093
- return c .systemDB .send (c , input )
1086
+ func (c * dbosContext ) Send (_ DBOSContext , destinationID string , message any , topic string ) error {
1087
+ return c .systemDB .send (c , WorkflowSendInput {
1088
+ DestinationID : destinationID ,
1089
+ Message : message ,
1090
+ Topic : topic ,
1091
+ })
1094
1092
}
1095
1093
1096
1094
// Send sends a message to another workflow with type safety.
1097
- // The message type R is automatically registered for gob encoding.
1095
+ // The message type P is automatically registered for gob encoding.
1098
1096
//
1099
1097
// Send can be called from within a workflow (as a durable step) or from outside workflows.
1100
1098
// When called within a workflow, the send operation becomes part of the workflow's durable state.
1101
1099
//
1102
1100
// Example:
1103
1101
//
1104
- // err := dbos.Send(ctx, dbos.GenericWorkflowSendInput[string]{
1105
- // DestinationID: "target-workflow-id",
1106
- // Message: "Hello from sender",
1107
- // Topic: "notifications",
1108
- // })
1109
- func Send [P any ](ctx DBOSContext , input GenericWorkflowSendInput [P ]) error {
1102
+ // err := dbos.Send(ctx, "target-workflow-id", "Hello from sender", "notifications")
1103
+ func Send [P any ](ctx DBOSContext , destinationID string , message P , topic string ) error {
1110
1104
if ctx == nil {
1111
1105
return errors .New ("ctx cannot be nil" )
1112
1106
}
1113
1107
var typedMessage P
1114
1108
gob .Register (typedMessage )
1115
- return ctx .Send (ctx , WorkflowSendInput {
1116
- DestinationID : input .DestinationID ,
1117
- Message : input .Message ,
1118
- Topic : input .Topic ,
1119
- })
1109
+ return ctx .Send (ctx , destinationID , message , topic )
1120
1110
}
1121
1111
1122
- // WorkflowRecvInput defines the parameters for receiving messages sent to this workflow.
1123
- type WorkflowRecvInput struct {
1112
+ // recvInput defines the parameters for receiving messages sent to this workflow.
1113
+ type recvInput struct {
1124
1114
Topic string // Topic to listen for (empty string receives from default topic)
1125
1115
Timeout time.Duration // Maximum time to wait for a message
1126
1116
}
1127
1117
1128
- func (c * dbosContext ) Recv (_ DBOSContext , input WorkflowRecvInput ) (any , error ) {
1118
+ func (c * dbosContext ) Recv (_ DBOSContext , topic string , timeout time.Duration ) (any , error ) {
1119
+ input := recvInput {
1120
+ Topic : topic ,
1121
+ Timeout : timeout ,
1122
+ }
1129
1123
return c .systemDB .recv (c , input )
1130
1124
}
1131
1125
@@ -1138,20 +1132,17 @@ func (c *dbosContext) Recv(_ DBOSContext, input WorkflowRecvInput) (any, error)
1138
1132
//
1139
1133
// Example:
1140
1134
//
1141
- // message, err := dbos.Recv[string](ctx, dbos.WorkflowRecvInput{
1142
- // Topic: "notifications",
1143
- // Timeout: 30 * time.Second,
1144
- // })
1135
+ // message, err := dbos.Recv[string](ctx, "notifications", 30 * time.Second)
1145
1136
// if err != nil {
1146
1137
// // Handle timeout or error
1147
1138
// return err
1148
1139
// }
1149
1140
// log.Printf("Received: %s", message)
1150
- func Recv [R any ](ctx DBOSContext , input WorkflowRecvInput ) (R , error ) {
1141
+ func Recv [R any ](ctx DBOSContext , topic string , timeout time. Duration ) (R , error ) {
1151
1142
if ctx == nil {
1152
1143
return * new (R ), errors .New ("ctx cannot be nil" )
1153
1144
}
1154
- msg , err := ctx .Recv (ctx , input )
1145
+ msg , err := ctx .Recv (ctx , topic , timeout )
1155
1146
if err != nil {
1156
1147
return * new (R ), err
1157
1148
}
@@ -1167,49 +1158,45 @@ func Recv[R any](ctx DBOSContext, input WorkflowRecvInput) (R, error) {
1167
1158
return typedMessage , nil
1168
1159
}
1169
1160
1170
- // GenericWorkflowSetEventInput defines the parameters for setting a workflow event.
1171
- type GenericWorkflowSetEventInput [P any ] struct {
1172
- Key string // Event key identifier
1173
- Message P // Event value (must be gob-encodable)
1174
- }
1175
-
1176
- func (c * dbosContext ) SetEvent (_ DBOSContext , input WorkflowSetEventInput ) error {
1177
- return c .systemDB .setEvent (c , input )
1161
+ func (c * dbosContext ) SetEvent (_ DBOSContext , key string , message any ) error {
1162
+ return c .systemDB .setEvent (c , WorkflowSetEventInput {
1163
+ Key : key ,
1164
+ Message : message ,
1165
+ })
1178
1166
}
1179
1167
1180
1168
// SetEvent sets a key-value event for the current workflow with type safety.
1181
1169
// Events are persistent and can be retrieved by other workflows using GetEvent.
1182
- // The event type R is automatically registered for gob encoding.
1170
+ // The event type P is automatically registered for gob encoding.
1183
1171
//
1184
1172
// SetEvent can only be called from within a workflow and becomes part of the workflow's durable state.
1185
1173
// Setting an event with the same key will overwrite the previous value.
1186
1174
//
1187
1175
// Example:
1188
1176
//
1189
- // err := dbos.SetEvent(ctx, dbos.GenericWorkflowSetEventInput[string]{
1190
- // Key: "status",
1191
- // Message: "processing-complete",
1192
- // })
1193
- func SetEvent [P any ](ctx DBOSContext , input GenericWorkflowSetEventInput [P ]) error {
1177
+ // err := dbos.SetEvent(ctx, "status", "processing-complete")
1178
+ func SetEvent [P any ](ctx DBOSContext , key string , message P ) error {
1194
1179
if ctx == nil {
1195
1180
return errors .New ("ctx cannot be nil" )
1196
1181
}
1197
1182
var typedMessage P
1198
1183
gob .Register (typedMessage )
1199
- return ctx .SetEvent (ctx , WorkflowSetEventInput {
1200
- Key : input .Key ,
1201
- Message : input .Message ,
1202
- })
1184
+ return ctx .SetEvent (ctx , key , message )
1203
1185
}
1204
1186
1205
- // WorkflowGetEventInput defines the parameters for retrieving an event from a workflow.
1206
- type WorkflowGetEventInput struct {
1187
+ // getEventInput defines the parameters for retrieving an event from a workflow.
1188
+ type getEventInput struct {
1207
1189
TargetWorkflowID string // Workflow ID to get the event from
1208
1190
Key string // Event key to retrieve
1209
1191
Timeout time.Duration // Maximum time to wait for the event to be set
1210
1192
}
1211
1193
1212
- func (c * dbosContext ) GetEvent (_ DBOSContext , input WorkflowGetEventInput ) (any , error ) {
1194
+ func (c * dbosContext ) GetEvent (_ DBOSContext , targetWorkflowID string , key string , timeout time.Duration ) (any , error ) {
1195
+ input := getEventInput {
1196
+ TargetWorkflowID : targetWorkflowID ,
1197
+ Key : key ,
1198
+ Timeout : timeout ,
1199
+ }
1213
1200
return c .systemDB .getEvent (c , input )
1214
1201
}
1215
1202
@@ -1221,21 +1208,17 @@ func (c *dbosContext) GetEvent(_ DBOSContext, input WorkflowGetEventInput) (any,
1221
1208
//
1222
1209
// Example:
1223
1210
//
1224
- // status, err := dbos.GetEvent[string](ctx, dbos.WorkflowGetEventInput{
1225
- // TargetWorkflowID: "target-workflow-id",
1226
- // Key: "status",
1227
- // Timeout: 30 * time.Second,
1228
- // })
1211
+ // status, err := dbos.GetEvent[string](ctx, "target-workflow-id", "status", 30 * time.Second)
1229
1212
// if err != nil {
1230
1213
// // Handle timeout or error
1231
1214
// return err
1232
1215
// }
1233
1216
// log.Printf("Status: %s", status)
1234
- func GetEvent [R any ](ctx DBOSContext , input WorkflowGetEventInput ) (R , error ) {
1217
+ func GetEvent [R any ](ctx DBOSContext , targetWorkflowID string , key string , timeout time. Duration ) (R , error ) {
1235
1218
if ctx == nil {
1236
1219
return * new (R ), errors .New ("ctx cannot be nil" )
1237
1220
}
1238
- value , err := ctx .GetEvent (ctx , input )
1221
+ value , err := ctx .GetEvent (ctx , targetWorkflowID , key , timeout )
1239
1222
if err != nil {
1240
1223
return * new (R ), err
1241
1224
}
@@ -1250,7 +1233,7 @@ func GetEvent[R any](ctx DBOSContext, input WorkflowGetEventInput) (R, error) {
1250
1233
return typedValue , nil
1251
1234
}
1252
1235
1253
- func (c * dbosContext ) Sleep (duration time.Duration ) (time.Duration , error ) {
1236
+ func (c * dbosContext ) Sleep (_ DBOSContext , duration time.Duration ) (time.Duration , error ) {
1254
1237
return c .systemDB .sleep (c , duration )
1255
1238
}
1256
1239
@@ -1269,7 +1252,7 @@ func Sleep(ctx DBOSContext, duration time.Duration) (time.Duration, error) {
1269
1252
if ctx == nil {
1270
1253
return 0 , errors .New ("ctx cannot be nil" )
1271
1254
}
1272
- return ctx .Sleep (duration )
1255
+ return ctx .Sleep (ctx , duration )
1273
1256
}
1274
1257
1275
1258
/***********************************/
@@ -1550,7 +1533,7 @@ func Enqueue[P any, R any](ctx DBOSContext, params GenericEnqueueOptions[P]) (Wo
1550
1533
// - workflowID: The unique identifier of the workflow to cancel
1551
1534
//
1552
1535
// Returns an error if the workflow does not exist or if the cancellation operation fails.
1553
- func (c * dbosContext ) CancelWorkflow (workflowID string ) error {
1536
+ func (c * dbosContext ) CancelWorkflow (_ DBOSContext , workflowID string ) error {
1554
1537
return c .systemDB .cancelWorkflow (c , workflowID )
1555
1538
}
1556
1539
@@ -1573,7 +1556,7 @@ func CancelWorkflow(ctx DBOSContext, workflowID string) error {
1573
1556
if ctx == nil {
1574
1557
return errors .New ("ctx cannot be nil" )
1575
1558
}
1576
- return ctx .CancelWorkflow (workflowID )
1559
+ return ctx .CancelWorkflow (ctx , workflowID )
1577
1560
}
1578
1561
1579
1562
func (c * dbosContext ) ResumeWorkflow (_ DBOSContext , workflowID string ) (WorkflowHandle [any ], error ) {
0 commit comments