Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Enrich TerminateExecution error to tell propeller the execution alrea…
Browse files Browse the repository at this point in the history
…dy terminated (#551)

* Enrich TerminateWorkflow error to tell propeller the execution already terminated

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>

* Fix unit test

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>

---------

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
  • Loading branch information
EngHabu authored Apr 16, 2023
1 parent 97a6aa4 commit 1026231
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pkg/manager/impl/execution_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,15 +1544,17 @@ func (m *ExecutionManager) TerminateExecution(
logger.Infof(ctx, "couldn't find execution [%+v] to save termination cause", request.Id)
return nil, err
}

if common.IsExecutionTerminal(core.WorkflowExecution_Phase(core.WorkflowExecution_Phase_value[executionModel.Phase])) {
return nil, errors.NewFlyteAdminError(codes.PermissionDenied, "Cannot abort an already terminate workflow execution")
return nil, errors.NewAlreadyInTerminalStateError(ctx, "Cannot abort an already terminate workflow execution", executionModel.Phase)
}

err = transformers.SetExecutionAborting(&executionModel, request.Cause, getUser(ctx))
if err != nil {
logger.Debugf(ctx, "failed to add abort metadata for execution [%+v] with err: %v", request.Id, err)
return nil, err
}

err = m.db.ExecutionRepo().Update(ctx, executionModel)
if err != nil {
logger.Debugf(ctx, "failed to save abort cause for terminated execution: %+v with err: %v", request.Id, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/impl/execution_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ func TestTerminateExecution_AlreadyTerminated(t *testing.T) {
assert.Nil(t, resp)
s, ok := status.FromError(err)
assert.True(t, ok)
assert.Equal(t, codes.PermissionDenied, s.Code())
assert.Equal(t, codes.FailedPrecondition, s.Code())
}

func TestGetExecutionData(t *testing.T) {
Expand Down

0 comments on commit 1026231

Please sign in to comment.