11package workflow
22
33import (
4+ "context"
45 "fmt"
56 "net/http"
67 "net/url"
@@ -37,9 +38,10 @@ type EngineImpl struct {
3738var _ Engine = (* EngineImpl )(nil )
3839
3940type engineRuntimeConfig struct {
40- config configuration.Configuration
41- input []Data
42- ic analytics.InstrumentationCollector
41+ config configuration.Configuration
42+ input []Data
43+ ic analytics.InstrumentationCollector
44+ ctxFunc func () context.Context
4345}
4446
4547type EngineInvokeOption func (* engineRuntimeConfig )
@@ -62,6 +64,12 @@ func WithInstrumentationCollector(ic analytics.InstrumentationCollector) EngineI
6264 }
6365}
6466
67+ func WithContext (ctx context.Context ) EngineInvokeOption {
68+ return func (e * engineRuntimeConfig ) {
69+ e .ctxFunc = func () context.Context { return ctx }
70+ }
71+ }
72+
6573func (e * EngineImpl ) GetLogger () * zerolog.Logger {
6674 return e .logger
6775}
@@ -321,11 +329,11 @@ func (e *EngineImpl) Invoke(
321329 e .mu .Unlock ()
322330
323331 // create a context object for the invocation
324- context := NewInvocationContext (id , options .config , localEngine , localNetworkAccess , localLogger , localAnalytics , localUi )
332+ invocationCtx := NewInvocationContext (options . ctxFunc , id , options .config , localEngine , localNetworkAccess , localLogger , localAnalytics , localUi )
325333
326334 // invoke workflow through its callback
327335 localLogger .Printf ("Workflow Start" )
328- output , err = callback (context , options .input )
336+ output , err = callback (invocationCtx , options .input )
329337 localLogger .Printf ("Workflow End" )
330338 }
331339 } else {
0 commit comments