From 5ec65be58f7d182c315ed0ad988166c443a2b40b Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 4 Nov 2019 13:18:05 +0200 Subject: [PATCH] Updated ActionTiming.Execute to return ErrPartiallyExecuted if not all actions were successfully --- engine/action_plan.go | 10 +++++++++- engine/actions_test.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/action_plan.go b/engine/action_plan.go index b3ee82af2..de3a1a095 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -294,7 +294,8 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err utils.Logger.Err(fmt.Sprintf("Failed to get actions for %s: %s", at.ActionsID, err)) return } - for accID, _ := range at.accountIDs { + var partialyExecuted bool + for accID := range at.accountIDs { _, err = guardian.Guardian.Guard(func() (interface{}, error) { acc, err := dm.DataDB().GetAccount(accID) if err != nil { @@ -331,11 +332,13 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err // do not allow the action plan to be rescheduled at.Timing = nil utils.Logger.Err(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType)) + partialyExecuted = true transactionFailed = true break } if err := actionFunction(acc, a, aac, at.ExtraData); err != nil { utils.Logger.Err(fmt.Sprintf("Error executing action %s: %v!", a.ActionType, err)) + partialyExecuted = true transactionFailed = true if failedActions != nil { go func() { failedActions <- a }() @@ -371,6 +374,7 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err // do not allow the action plan to be rescheduled at.Timing = nil utils.Logger.Err(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType)) + partialyExecuted = true if failedActions != nil { go func() { failedActions <- a }() } @@ -378,6 +382,7 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err } if err := actionFunction(nil, a, aac, at.ExtraData); err != nil { utils.Logger.Err(fmt.Sprintf("Error executing accountless action %s: %v!", a.ActionType, err)) + partialyExecuted = true if failedActions != nil { go func() { failedActions <- a }() } @@ -392,6 +397,9 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err utils.Logger.Warning(fmt.Sprintf("Error executing action plan: %v", err)) return err } + if partialyExecuted { + return utils.ErrPartiallyExecuted + } return } diff --git a/engine/actions_test.go b/engine/actions_test.go index 547f125d6..fd01b7820 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -445,7 +445,7 @@ func TestActionPlanFunctionNotAvailable(t *testing.T) { actions: []*Action{a}, } err := at.Execute(nil, nil) - if err != nil { + if err != utils.ErrPartiallyExecuted { // because we want to return err if we can't execute all actions t.Errorf("Faild to detect wrong function type: %v", err) } }