2021-11-13 21:18:06 +02:00
|
|
|
// Copyright 2021 Woodpecker Authors
|
2018-02-20 00:24:10 +02:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +02:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +02:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-03-28 10:53:06 +02:00
|
|
|
package model
|
|
|
|
|
2022-10-28 17:38:53 +02:00
|
|
|
// StepStore persists process information to storage.
|
|
|
|
type StepStore interface {
|
|
|
|
StepLoad(int64) (*Step, error)
|
|
|
|
StepFind(*Pipeline, int) (*Step, error)
|
|
|
|
StepChild(*Pipeline, int, string) (*Step, error)
|
|
|
|
StepList(*Pipeline) ([]*Step, error)
|
|
|
|
StepCreate([]*Step) error
|
|
|
|
StepUpdate(*Step) error
|
|
|
|
StepClear(*Pipeline) error
|
2017-03-28 10:53:06 +02:00
|
|
|
}
|
|
|
|
|
2023-06-29 14:56:01 +02:00
|
|
|
// Different ways to handle failure states
|
|
|
|
const (
|
|
|
|
FailureIgnore = "ignore"
|
|
|
|
FailureFail = "fail"
|
|
|
|
// FailureCancel = "cancel" // Not implemented yet
|
|
|
|
)
|
|
|
|
|
2022-10-28 17:38:53 +02:00
|
|
|
// Step represents a process in the pipeline.
|
|
|
|
type Step struct {
|
2023-06-27 18:01:18 +02:00
|
|
|
ID int64 `json:"id" xorm:"pk autoincr 'step_id'"`
|
2023-07-08 20:09:53 +02:00
|
|
|
UUID string `json:"uuid" xorm:"INDEX 'step_uuid'"`
|
2023-06-27 18:01:18 +02:00
|
|
|
PipelineID int64 `json:"pipeline_id" xorm:"UNIQUE(s) INDEX 'step_pipeline_id'"`
|
|
|
|
PID int `json:"pid" xorm:"UNIQUE(s) 'step_pid'"`
|
|
|
|
PPID int `json:"ppid" xorm:"step_ppid"`
|
|
|
|
Name string `json:"name" xorm:"step_name"`
|
|
|
|
State StatusValue `json:"state" xorm:"step_state"`
|
2023-07-08 20:09:53 +02:00
|
|
|
Error string `json:"error,omitempty" xorm:"TEXT 'step_error'"`
|
2023-06-29 14:56:01 +02:00
|
|
|
Failure string `json:"-" xorm:"step_failure"`
|
2023-06-27 18:01:18 +02:00
|
|
|
ExitCode int `json:"exit_code" xorm:"step_exit_code"`
|
|
|
|
Started int64 `json:"start_time,omitempty" xorm:"step_started"`
|
|
|
|
Stopped int64 `json:"end_time,omitempty" xorm:"step_stopped"`
|
2023-07-11 15:53:05 +02:00
|
|
|
Type StepType `json:"type,omitempty" xorm:"step_type"`
|
2023-06-03 21:38:36 +02:00
|
|
|
} // @name Step
|
2021-11-13 21:18:06 +02:00
|
|
|
|
2022-10-28 17:38:53 +02:00
|
|
|
type UpdateStepStore interface {
|
|
|
|
StepUpdate(*Step) error
|
2022-06-16 15:35:58 +02:00
|
|
|
}
|
|
|
|
|
2021-11-13 21:18:06 +02:00
|
|
|
// TableName return database table name for xorm
|
2022-10-28 17:38:53 +02:00
|
|
|
func (Step) TableName() string {
|
|
|
|
return "steps"
|
2017-03-28 10:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Running returns true if the process state is pending or running.
|
2022-10-28 17:38:53 +02:00
|
|
|
func (p *Step) Running() bool {
|
2017-03-28 10:53:06 +02:00
|
|
|
return p.State == StatusPending || p.State == StatusRunning
|
|
|
|
}
|
|
|
|
|
|
|
|
// Failing returns true if the process state is failed, killed or error.
|
2022-10-28 17:38:53 +02:00
|
|
|
func (p *Step) Failing() bool {
|
2023-06-29 14:56:01 +02:00
|
|
|
return p.Failure == FailureFail && (p.State == StatusError || p.State == StatusKilled || p.State == StatusFailure)
|
2017-03-28 10:53:06 +02:00
|
|
|
}
|
2023-07-11 15:53:05 +02:00
|
|
|
|
|
|
|
// StepType identifies the type of step
|
|
|
|
type StepType string // @name StepType
|
|
|
|
|
|
|
|
const (
|
|
|
|
StepTypeClone StepType = "clone"
|
|
|
|
StepTypeService StepType = "service"
|
|
|
|
StepTypePlugin StepType = "plugin"
|
|
|
|
StepTypeCommands StepType = "commands"
|
|
|
|
StepTypeCache StepType = "cache"
|
|
|
|
)
|