Skip to content

Commit

Permalink
fix: not reusing success messages (#577)
Browse files Browse the repository at this point in the history
The reusable Success message should be immutable, but it seems harder to
maintain the immutability. There has been cases where the Success
message was contaminated with failure message, which requires a restart
to clear. Using a disposable success message seems safer and easier.
  • Loading branch information
Charles546 committed Oct 27, 2023
1 parent d7c8d52 commit 2b12221
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions internal/workflow/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import (
"github.com/mitchellh/mapstructure"
)

var Success = &dipper.Message{
Labels: map[string]string{
"status": SessionStatusSuccess,
},
// Success returns a empty message with success status.
func Success() *dipper.Message {
return &dipper.Message{
Labels: map[string]string{
"status": SessionStatusSuccess,
},
}
}

// execute is the entry point of the workflow.
Expand Down Expand Up @@ -73,7 +76,7 @@ func (w *Session) execute(msg *dipper.Message) {
// noop continues the workflow as doing nothing.
func (w *Session) noop(msg *dipper.Message) {
if msg.Labels["status"] != "success" {
msg = Success
msg = Success()
}
if w.ID != "" {
w.continueExec(msg, nil)
Expand Down Expand Up @@ -314,7 +317,7 @@ func (w *Session) executeAction(msg *dipper.Message) {
defer dipper.SafeExitOnError("Failed in execute detached workflow %+v", w.workflow.Workflow)
child.execute(msg)
})
w.continueExec(Success, nil)
w.continueExec(Success(), nil)
} else {
child.execute(msg)
}
Expand Down Expand Up @@ -343,7 +346,7 @@ func (w *Session) executeAction(msg *dipper.Message) {
w.performing = "switch"
w.executeSwitch(msg)
default:
w.continueExec(Success, nil)
w.continueExec(Success(), nil)
}
}

Expand Down

0 comments on commit 2b12221

Please sign in to comment.