Skip to content

Commit 173c850

Browse files
committed
pass around launched when creating child contexts
1 parent 0a801e5 commit 173c850

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

dbos/dbos.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
194194
}
195195
// Will do nothing if the concrete type is not dbosContext
196196
if dbosCtx, ok := ctx.(*dbosContext); ok {
197+
launched := dbosCtx.launched.Load()
198+
childCtxLaunched := atomic.Bool{}
199+
childCtxLaunched.Store(launched)
197200
return &dbosContext{
198201
ctx: context.WithValue(dbosCtx.ctx, key, val), // Spawn a new child context with the value set
199202
logger: dbosCtx.logger,
@@ -204,6 +207,7 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
204207
applicationVersion: dbosCtx.applicationVersion,
205208
executorID: dbosCtx.executorID,
206209
applicationID: dbosCtx.applicationID,
210+
launched: childCtxLaunched,
207211
}
208212
}
209213
return nil
@@ -217,6 +221,11 @@ func WithoutCancel(ctx DBOSContext) DBOSContext {
217221
return nil
218222
}
219223
if dbosCtx, ok := ctx.(*dbosContext); ok {
224+
launched := dbosCtx.launched.Load()
225+
childCtxLaunched := atomic.Bool{}
226+
childCtxLaunched.Store(launched)
227+
// Create a new context that is not canceled when the parent is canceled
228+
// but retains all other values
220229
return &dbosContext{
221230
ctx: context.WithoutCancel(dbosCtx.ctx),
222231
logger: dbosCtx.logger,
@@ -227,6 +236,7 @@ func WithoutCancel(ctx DBOSContext) DBOSContext {
227236
applicationVersion: dbosCtx.applicationVersion,
228237
executorID: dbosCtx.executorID,
229238
applicationID: dbosCtx.applicationID,
239+
launched: childCtxLaunched,
230240
}
231241
}
232242
return nil
@@ -240,6 +250,9 @@ func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.C
240250
return nil, func() {}
241251
}
242252
if dbosCtx, ok := ctx.(*dbosContext); ok {
253+
launched := dbosCtx.launched.Load()
254+
childCtxLaunched := atomic.Bool{}
255+
childCtxLaunched.Store(launched)
243256
newCtx, cancelFunc := context.WithTimeoutCause(dbosCtx.ctx, timeout, errors.New("DBOS context timeout"))
244257
return &dbosContext{
245258
ctx: newCtx,
@@ -251,6 +264,7 @@ func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.C
251264
applicationVersion: dbosCtx.applicationVersion,
252265
executorID: dbosCtx.executorID,
253266
applicationID: dbosCtx.applicationID,
267+
launched: childCtxLaunched,
254268
}, cancelFunc
255269
}
256270
return nil, func() {}

0 commit comments

Comments
 (0)