Skip to content

Commit 68f07ca

Browse files
committed
store pointers to sync.Map and also pass workflowCustomNametoFQN to new contexts
1 parent 91d8e90 commit 68f07ca

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

dbos/dbos.go

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ type dbosContext struct {
121121
workflowsWg *sync.WaitGroup
122122

123123
// Workflow registry - read-mostly sync.Map since registration happens only before launch
124-
workflowRegistry sync.Map // map[string]workflowRegistryEntry
125-
workflowCustomNametoFQN sync.Map // Maps fully qualified workflow names to custom names. Usefor when client enqueues a workflow by name because registry is indexed by FQN.
124+
workflowRegistry *sync.Map // map[string]workflowRegistryEntry
125+
workflowCustomNametoFQN *sync.Map // Maps fully qualified workflow names to custom names. Usefor when client enqueues a workflow by name because registry is indexed by FQN.
126126

127127
// Workflow scheduler
128128
workflowScheduler *cron.Cron
@@ -158,14 +158,15 @@ func WithValue(ctx DBOSContext, key, val any) DBOSContext {
158158
// Will do nothing if the concrete type is not dbosContext
159159
if dbosCtx, ok := ctx.(*dbosContext); ok {
160160
return &dbosContext{
161-
ctx: context.WithValue(dbosCtx.ctx, key, val), // Spawn a new child context with the value set
162-
logger: dbosCtx.logger,
163-
systemDB: dbosCtx.systemDB,
164-
workflowsWg: dbosCtx.workflowsWg,
165-
workflowRegistry: dbosCtx.workflowRegistry,
166-
applicationVersion: dbosCtx.applicationVersion,
167-
executorID: dbosCtx.executorID,
168-
applicationID: dbosCtx.applicationID,
161+
ctx: context.WithValue(dbosCtx.ctx, key, val), // Spawn a new child context with the value set
162+
logger: dbosCtx.logger,
163+
systemDB: dbosCtx.systemDB,
164+
workflowsWg: dbosCtx.workflowsWg,
165+
workflowRegistry: dbosCtx.workflowRegistry,
166+
workflowCustomNametoFQN: dbosCtx.workflowCustomNametoFQN,
167+
applicationVersion: dbosCtx.applicationVersion,
168+
executorID: dbosCtx.executorID,
169+
applicationID: dbosCtx.applicationID,
169170
}
170171
}
171172
return nil
@@ -180,14 +181,15 @@ func WithoutCancel(ctx DBOSContext) DBOSContext {
180181
}
181182
if dbosCtx, ok := ctx.(*dbosContext); ok {
182183
return &dbosContext{
183-
ctx: context.WithoutCancel(dbosCtx.ctx),
184-
logger: dbosCtx.logger,
185-
systemDB: dbosCtx.systemDB,
186-
workflowsWg: dbosCtx.workflowsWg,
187-
workflowRegistry: dbosCtx.workflowRegistry,
188-
applicationVersion: dbosCtx.applicationVersion,
189-
executorID: dbosCtx.executorID,
190-
applicationID: dbosCtx.applicationID,
184+
ctx: context.WithoutCancel(dbosCtx.ctx),
185+
logger: dbosCtx.logger,
186+
systemDB: dbosCtx.systemDB,
187+
workflowsWg: dbosCtx.workflowsWg,
188+
workflowRegistry: dbosCtx.workflowRegistry,
189+
workflowCustomNametoFQN: dbosCtx.workflowCustomNametoFQN,
190+
applicationVersion: dbosCtx.applicationVersion,
191+
executorID: dbosCtx.executorID,
192+
applicationID: dbosCtx.applicationID,
191193
}
192194
}
193195
return nil
@@ -203,14 +205,15 @@ func WithTimeout(ctx DBOSContext, timeout time.Duration) (DBOSContext, context.C
203205
if dbosCtx, ok := ctx.(*dbosContext); ok {
204206
newCtx, cancelFunc := context.WithTimeoutCause(dbosCtx.ctx, timeout, errors.New("DBOS context timeout"))
205207
return &dbosContext{
206-
ctx: newCtx,
207-
logger: dbosCtx.logger,
208-
systemDB: dbosCtx.systemDB,
209-
workflowsWg: dbosCtx.workflowsWg,
210-
workflowRegistry: dbosCtx.workflowRegistry,
211-
applicationVersion: dbosCtx.applicationVersion,
212-
executorID: dbosCtx.executorID,
213-
applicationID: dbosCtx.applicationID,
208+
ctx: newCtx,
209+
logger: dbosCtx.logger,
210+
systemDB: dbosCtx.systemDB,
211+
workflowsWg: dbosCtx.workflowsWg,
212+
workflowRegistry: dbosCtx.workflowRegistry,
213+
workflowCustomNametoFQN: dbosCtx.workflowCustomNametoFQN,
214+
applicationVersion: dbosCtx.applicationVersion,
215+
executorID: dbosCtx.executorID,
216+
applicationID: dbosCtx.applicationID,
214217
}, cancelFunc
215218
}
216219
return nil, func() {}
@@ -258,9 +261,11 @@ func (c *dbosContext) GetApplicationID() string {
258261
func NewDBOSContext(inputConfig Config) (DBOSContext, error) {
259262
ctx, cancelFunc := context.WithCancelCause(context.Background())
260263
initExecutor := &dbosContext{
261-
workflowsWg: &sync.WaitGroup{},
262-
ctx: ctx,
263-
ctxCancelFunc: cancelFunc,
264+
workflowsWg: &sync.WaitGroup{},
265+
ctx: ctx,
266+
ctxCancelFunc: cancelFunc,
267+
workflowRegistry: &sync.Map{},
268+
workflowCustomNametoFQN: &sync.Map{},
264269
}
265270

266271
// Load and process the configuration

0 commit comments

Comments
 (0)