-
Notifications
You must be signed in to change notification settings - Fork 18
fix: apply invocation config to workflow Data after callback #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,10 +66,18 @@ func withPayload(payload *interface{}) Option { | |
| } | ||
| } | ||
|
|
||
| // WithConfiguration copies IN_MEMORY_THRESHOLD_BYTES and TEMP_DIR_PATH from | ||
| // config when each key resolves to a value (including AddDefaultValue). If | ||
| // TEMP_DIR_PATH is absent, d.tempDirPath is left unchanged (typically ""), and | ||
| // os.CreateTemp uses the process default temp directory. | ||
| func WithConfiguration(config configuration.Configuration) Option { | ||
| return func(d *DataImpl) { | ||
| d.inMemoryThreshold = config.GetInt(configuration.IN_MEMORY_THRESHOLD_BYTES) | ||
| d.tempDirPath = config.GetString(configuration.TEMP_DIR_PATH) | ||
| if v := config.Get(configuration.IN_MEMORY_THRESHOLD_BYTES); v != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: exported-API semantic change worth a direct-caller test. |
||
| d.inMemoryThreshold = config.GetInt(configuration.IN_MEMORY_THRESHOLD_BYTES) | ||
| } | ||
| if v := config.Get(configuration.TEMP_DIR_PATH); v != nil { | ||
| d.tempDirPath = config.GetString(configuration.TEMP_DIR_PATH) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -256,6 +264,28 @@ func (d *DataImpl) AddError(err snyk_errors.Error) { | |
| d.errors = append(d.errors, err) | ||
| } | ||
|
|
||
| // applyConfiguration re-evaluates the payload location using the given | ||
| // configuration. Field updates use the same rules as WithConfiguration. | ||
| // If the payload is currently in memory and exceeds the | ||
| // configured threshold, it is written to disk under the configured temp | ||
| // directory. This allows the engine to apply its configuration to Data | ||
| // objects that were created without WithConfiguration. | ||
| func (d *DataImpl) applyConfiguration(config configuration.Configuration) { | ||
| if config.Get(configuration.IN_MEMORY_THRESHOLD_BYTES) == nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should-Fix (correctness): new nil-config panic path. |
||
| return | ||
| } | ||
|
|
||
| WithConfiguration(config)(d) | ||
|
|
||
| if d.payloadLocation.Type == InMemory && d.payload != nil { | ||
| d.payloadLocation = setPayloadLocation(d.identifier, d.inMemoryThreshold, d.tempDirPath, d.payload, d.logger) | ||
| if d.payloadLocation.Type == OnDisk { | ||
| d.logger.Debug().Msg("payload relocated to disk after applyConfiguration") | ||
| d.payload = nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func setPayloadLocation(id Identifier, inMemoryThreshold int, tempDirPath string, payload interface{}, logger *zerolog.Logger) Location { | ||
| payloadLocation := Location{ | ||
| Path: "", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,6 +338,15 @@ func (e *EngineImpl) Invoke( | |
| localLogger.Printf("Workflow Start") | ||
| output, err = callback(invocationCtx, options.input) | ||
| localLogger.Printf("Workflow End") | ||
|
|
||
| // Apply the engine's configuration to output data so that | ||
| // IN_MEMORY_THRESHOLD_BYTES and TEMP_DIR_PATH are respected | ||
| // even when workflows create Data without WithConfiguration. | ||
| for _, d := range output { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: relocation runs even when the callback returned an error. This loop is outside any |
||
| if di, ok := d.(*DataImpl); ok { | ||
| di.applyConfiguration(options.config) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should-Fix (contract): engine silently overrides a workflow's explicit |
||
| } | ||
| } | ||
| } | ||
| } else { | ||
| err = fmt.Errorf("workflow '%v' not found", id) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in an ideal world (at least the one in my head) there should be a receiver
func (d *DataImpl) WithConfiguration(...). As this may be problematic to implement now (too many usages off the task scope), I suggest the following:what do you think - this doesn't change the existing signatures which is probably used from other places, while keeping the state in the receiver