-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: failure to commit leads to inconsistencies between workflow and database #302
Draft
rbeuque74
wants to merge
2
commits into
master
Choose a base branch
from
dev/rbeuque/fix-fail-to-commit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,12 +264,14 @@ func (e Engine) launchResolution(publicID string, async bool, sm *semaphore.Weig | |
} | ||
debugLogger.Debugf("Engine: Resolve() %s RECAP BEFORE resolve: state: %s, steps: %s", publicID, res.State, strings.Join(recap, ", ")) | ||
e.wg.Add(1) | ||
|
||
err = nil | ||
if async { | ||
go resolve(dbp, res, t, sm, e.wg, debugLogger) | ||
} else { | ||
resolve(dbp, res, t, sm, e.wg, debugLogger) | ||
err = resolve(dbp, res, t, sm, e.wg, debugLogger) | ||
} | ||
return res, nil | ||
return res, err | ||
} | ||
|
||
func initialize(dbp zesty.DBProvider, publicID string, debugLogger *logrus.Entry) (*resolution.Resolution, *task.Task, error) { | ||
|
@@ -377,13 +379,17 @@ func initialize(dbp zesty.DBProvider, publicID string, debugLogger *logrus.Entry | |
return res, t, nil | ||
} | ||
|
||
func resolve(dbp zesty.DBProvider, res *resolution.Resolution, t *task.Task, sm *semaphore.Weighted, wg *sync.WaitGroup, debugLogger *logrus.Entry) { | ||
func resolve(dbp zesty.DBProvider, res *resolution.Resolution, t *task.Task, sm *semaphore.Weighted, wg *sync.WaitGroup, debugLogger *logrus.Entry) error { | ||
defer wg.Done() | ||
// keep track of steps which get executed during each run, to avoid looping+retrying the same failing step endlessly | ||
executedSteps := map[string]bool{} | ||
stepChan := make(chan *step.Step) | ||
|
||
expectedMessages := runAvailableSteps(dbp, map[string]bool{}, res, t, stepChan, executedSteps, []string{}, wg, debugLogger) | ||
expectedMessages, err := runAvailableSteps(dbp, map[string]bool{}, res, stepChan, executedSteps, []string{}, wg, debugLogger) | ||
if err != nil { | ||
debugLogger.Debugf("Engine: resolve() %s loop, ERROR WHILE runAvailableSteps: %s", res.PublicID, err) | ||
return err | ||
} | ||
|
||
for expectedMessages > 0 { | ||
debugLogger.Debugf("Engine: resolve() %s loop, %d expected steps", res.PublicID, expectedMessages) | ||
|
@@ -451,7 +457,13 @@ func resolve(dbp zesty.DBProvider, res *resolution.Resolution, t *task.Task, sm | |
// one less step to go | ||
expectedMessages-- | ||
// state change might unlock more steps for execution | ||
expectedMessages += runAvailableSteps(dbp, modifiedSteps, res, t, stepChan, executedSteps, []string{}, wg, debugLogger) | ||
newAvailableSteps, err := runAvailableSteps(dbp, modifiedSteps, res, stepChan, executedSteps, []string{}, wg, debugLogger) | ||
if err != nil { | ||
debugLogger.Debugf("Engine: resolve() %s loop, ERROR WHILE runAvailableSteps: %s", res.PublicID, err) | ||
return err | ||
} | ||
|
||
expectedMessages += newAvailableSteps | ||
|
||
// attempt to persist all changes in db | ||
if err := commit(dbp, res, t); err != nil { | ||
|
@@ -584,6 +596,8 @@ func resolve(dbp zesty.DBProvider, res *resolution.Resolution, t *task.Task, sm | |
if err := resumeParentTask(dbp, t, sm, debugLogger); err != nil { | ||
debugLogger.WithError(err).Debugf("Engine: resolver(): failed to resume parent task: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resumeParentTask(dbp zesty.DBProvider, currentTask *task.Task, sm *semaphore.Weighted, debugLogger *logrus.Entry) error { | ||
|
@@ -639,15 +653,15 @@ func commit(dbp zesty.DBProvider, res *resolution.Resolution, t *task.Task) erro | |
return dbp.Commit() | ||
} | ||
|
||
func runAvailableSteps(dbp zesty.DBProvider, modifiedSteps map[string]bool, res *resolution.Resolution, t *task.Task, stepChan chan<- *step.Step, executedSteps map[string]bool, expandedSteps []string, wg *sync.WaitGroup, debugLogger *logrus.Entry) int { | ||
func runAvailableSteps(dbp zesty.DBProvider, modifiedSteps map[string]bool, res *resolution.Resolution, stepChan chan<- *step.Step, executedSteps map[string]bool, expandedSteps []string, wg *sync.WaitGroup, debugLogger *logrus.Entry) (int, error) { | ||
av := availableSteps(modifiedSteps, res, executedSteps, expandedSteps, debugLogger) | ||
expandedSteps = []string{} | ||
preRunModifiedSteps := map[string]bool{} | ||
expanded := 0 | ||
|
||
select { | ||
case <-shutdownCtx.Done(): | ||
return 0 | ||
return 0, nil | ||
default: | ||
for name, s := range av { | ||
// prepare step | ||
|
@@ -688,7 +702,9 @@ func runAvailableSteps(dbp zesty.DBProvider, modifiedSteps map[string]bool, res | |
} | ||
// rebuild step dependency tree to include generated loop steps | ||
res.BuildStepTree() | ||
commit(dbp, res, nil) | ||
if err := commit(dbp, res, nil); err != nil { | ||
return 0, err | ||
} | ||
go func() { stepChan <- s }() | ||
} else { // regular step | ||
s.ResultValidate = jsonschema.Validator(s.Name, s.Schema) | ||
|
@@ -699,7 +715,9 @@ func runAvailableSteps(dbp zesty.DBProvider, modifiedSteps map[string]bool, res | |
if s.State != step.StateAfterrunError { | ||
res.SetStepState(s.Name, step.StateRunning) | ||
step.PreRun(s, res.Values, resolutionStateSetter(res, preRunModifiedSteps), executedSteps) | ||
commit(dbp, res, nil) | ||
if err := commit(dbp, res, nil); err != nil { | ||
return 0, err | ||
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. Problem in my current implementation is that exiting the Not sure how we should handle this. |
||
} | ||
} | ||
|
||
// run | ||
|
@@ -714,10 +732,15 @@ func runAvailableSteps(dbp zesty.DBProvider, modifiedSteps map[string]bool, res | |
// - loop step generated new steps | ||
if len(preRunModifiedSteps) > 0 || expanded > 0 { | ||
pruneSteps(res, preRunModifiedSteps) | ||
return len(av) + runAvailableSteps(dbp, preRunModifiedSteps, res, t, stepChan, executedSteps, expandedSteps, wg, debugLogger) | ||
newAvailableSteps, err := runAvailableSteps(dbp, preRunModifiedSteps, res, stepChan, executedSteps, expandedSteps, wg, debugLogger) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return len(av) + newAvailableSteps, nil | ||
} | ||
|
||
return len(av) | ||
return len(av), nil | ||
} | ||
|
||
func expandStep(s *step.Step, res *resolution.Resolution) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Might be replaced with
return resolve(...), nil
, since there is nothing to do after theif
statement, which spares the declaration oferr
above.