*: add run cancel action
and remove unused change phase to finished
This commit is contained in:
parent
9cafc36a0d
commit
bda7a3eb8b
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/sorintlab/agola/internal/services/common"
|
||||
rsapi "github.com/sorintlab/agola/internal/services/runservice/api"
|
||||
rstypes "github.com/sorintlab/agola/internal/services/runservice/types"
|
||||
"github.com/sorintlab/agola/internal/util"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -104,6 +105,7 @@ type RunActionType string
|
|||
|
||||
const (
|
||||
RunActionTypeRestart RunActionType = "restart"
|
||||
RunActionTypeCancel RunActionType = "cancel"
|
||||
RunActionTypeStop RunActionType = "stop"
|
||||
)
|
||||
|
||||
|
@ -140,6 +142,17 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (
|
|||
return nil, ErrFromRemote(resp, err)
|
||||
}
|
||||
|
||||
case RunActionTypeCancel:
|
||||
rsreq := &rsapi.RunActionsRequest{
|
||||
ActionType: rsapi.RunActionTypeChangePhase,
|
||||
Phase: rstypes.RunPhaseCancelled,
|
||||
}
|
||||
|
||||
resp, err = h.runserviceClient.RunActions(ctx, req.RunID, rsreq)
|
||||
if err != nil {
|
||||
return nil, ErrFromRemote(resp, err)
|
||||
}
|
||||
|
||||
case RunActionTypeStop:
|
||||
rsreq := &rsapi.RunActionsRequest{
|
||||
ActionType: rsapi.RunActionTypeStop,
|
||||
|
|
|
@ -76,18 +76,25 @@ func (h *ActionHandler) ChangeRunPhase(ctx context.Context, req *RunChangePhaseR
|
|||
switch req.Phase {
|
||||
case types.RunPhaseRunning:
|
||||
if r.Phase != types.RunPhaseQueued {
|
||||
return errors.Errorf("run %s is not queued but in %q phase", r.ID, r.Phase)
|
||||
return errors.Errorf("run %q is not queued but in %q phase", r.ID, r.Phase)
|
||||
}
|
||||
r.ChangePhase(types.RunPhaseRunning)
|
||||
runEvent, err = common.NewRunEvent(ctx, h.e, r.ID, r.Phase, r.Result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case types.RunPhaseFinished:
|
||||
if r.Phase != types.RunPhaseRunning {
|
||||
return errors.Errorf("run %s is not running but in %q phase", r.ID, r.Phase)
|
||||
case types.RunPhaseCancelled:
|
||||
if r.Phase != types.RunPhaseQueued {
|
||||
return errors.Errorf("run %q is not queued but in %q phase", r.ID, r.Phase)
|
||||
}
|
||||
r.Stop = true
|
||||
r.ChangePhase(types.RunPhaseCancelled)
|
||||
runEvent, err = common.NewRunEvent(ctx, h.e, r.ID, r.Phase, r.Result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unsupport change phase %q", req.Phase)
|
||||
|
||||
}
|
||||
|
||||
_, err = store.AtomicPutRun(ctx, h.e, r, runEvent, cgt)
|
||||
|
|
Loading…
Reference in New Issue