Skip to content

Commit

Permalink
runner: fix execution order with struct slice instead of map
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Feb 1, 2024
1 parent aeff50c commit 388d981
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ func New(logger *logrus.Entry) *Runner {
}

func (r *Runner) RunTask(ctx context.Context, task *model.Task, handler Handler) error {
funcs := map[string]func(context.Context) error{
"Initialize": handler.Initialize,
"Query": handler.Query,
"PlanActions": handler.PlanActions,
"RunActions": handler.RunActions,
// nolint:govet // struct field optimization not required
funcs := []struct {
name string
method func(context.Context) error
}{
{"Initialize", handler.Initialize},
{"Query", handler.Query},
{"PlanActions", handler.PlanActions},
{"RunActions", handler.RunActions},
}

taskFailed := func(err error) error {
Expand Down Expand Up @@ -66,12 +70,12 @@ func (r *Runner) RunTask(ctx context.Context, task *model.Task, handler Handler)
_ = task.SetState(model.StateActive)
handler.Publish()

for fname, f := range funcs {
if cferr := r.conditionalFault(fname, task, handler); cferr != nil {
for _, f := range funcs {
if cferr := r.conditionalFault(f.name, task, handler); cferr != nil {
return taskFailed(cferr)
}

if err := f(ctx); err != nil {
if err := f.method(ctx); err != nil {
return taskFailed(err)
}
}
Expand Down

0 comments on commit 388d981

Please sign in to comment.