Updated ActionTiming.Execute to return ErrPartiallyExecuted if not all actions were successfully

This commit is contained in:
Trial97
2019-11-04 13:18:05 +02:00
committed by Dan Christian Bogos
parent a8988c74a6
commit 5ec65be58f
2 changed files with 10 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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)
}
}