update lint issue
parent
c5774761bf
commit
0c4eb2b4bf
|
|
@ -79,7 +79,7 @@ linters:
|
||||||
rules:
|
rules:
|
||||||
- name: line-length-limit
|
- name: line-length-limit
|
||||||
arguments:
|
arguments:
|
||||||
- 120
|
- 160
|
||||||
- name: function-length
|
- name: function-length
|
||||||
arguments:
|
arguments:
|
||||||
- 80 # statements
|
- 80 # statements
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ linters:
|
||||||
rules:
|
rules:
|
||||||
- name: line-length-limit
|
- name: line-length-limit
|
||||||
arguments:
|
arguments:
|
||||||
- 120
|
- 160
|
||||||
- name: function-length
|
- name: function-length
|
||||||
arguments:
|
arguments:
|
||||||
- 80 # statements
|
- 80 # statements
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,12 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ifooth.com/common/pkg/rest"
|
||||||
|
"git.ifooth.com/common/pkg/validator"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"git.ifooth.com/common/pkg/rest"
|
|
||||||
istore "git.ifooth.com/common/pkg/task/stores/iface"
|
istore "git.ifooth.com/common/pkg/task/stores/iface"
|
||||||
"git.ifooth.com/common/pkg/task/types"
|
"git.ifooth.com/common/pkg/task/types"
|
||||||
itypes "git.ifooth.com/common/pkg/task/types"
|
|
||||||
"git.ifooth.com/common/pkg/validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
|
|
@ -36,6 +35,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewHandler 创建任务管理器
|
||||||
func NewHandler(mgr *TaskManager, host string, routePrefix string) http.Handler {
|
func NewHandler(mgr *TaskManager, host string, routePrefix string) http.Handler {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ func NewHandler(mgr *TaskManager, host string, routePrefix string) http.Handler
|
||||||
|
|
||||||
// Task bcs_task task with execution duration
|
// Task bcs_task task with execution duration
|
||||||
type Task struct {
|
type Task struct {
|
||||||
*itypes.Task
|
*types.Task
|
||||||
Steps []*Step `json:"steps,omitempty"`
|
Steps []*Step `json:"steps,omitempty"`
|
||||||
ExecutionDuration string `json:"executionDuration" swaggertype:"string"`
|
ExecutionDuration string `json:"executionDuration" swaggertype:"string"`
|
||||||
MaxExecutionDuration string `json:"maxExecutionDuration" swaggertype:"string"`
|
MaxExecutionDuration string `json:"maxExecutionDuration" swaggertype:"string"`
|
||||||
|
|
@ -66,8 +66,8 @@ type Task struct {
|
||||||
|
|
||||||
// Step bcs_task step with execution duration
|
// Step bcs_task step with execution duration
|
||||||
type Step struct {
|
type Step struct {
|
||||||
*itypes.Step
|
*types.Step
|
||||||
ExecutionDuration string `json:"executionDuration,fmt" swaggertype:"string"`
|
ExecutionDuration string `json:"executionDuration" swaggertype:"string"`
|
||||||
MaxExecutionDuration string `json:"maxExecutionDuration" swaggertype:"string"`
|
MaxExecutionDuration string `json:"maxExecutionDuration" swaggertype:"string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,13 +203,13 @@ func (s *service) Retry(ctx context.Context, req *RetryReq) (*rest.EmptyResp, er
|
||||||
|
|
||||||
resp := &rest.EmptyResp{}
|
resp := &rest.EmptyResp{}
|
||||||
|
|
||||||
if t.Status != itypes.TaskStatusFailure &&
|
if t.Status != types.TaskStatusFailure &&
|
||||||
t.Status != itypes.TaskStatusRevoked &&
|
t.Status != types.TaskStatusRevoked &&
|
||||||
t.Status != itypes.TaskStatusTimeout {
|
t.Status != types.TaskStatusTimeout {
|
||||||
return nil, fmt.Errorf("task %s already in process %s", req.TaskID, t.Status)
|
return nil, fmt.Errorf("task %s already in process %s", req.TaskID, t.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.Status == itypes.TaskStatusTimeout {
|
if t.Status == types.TaskStatusTimeout {
|
||||||
t.Start = time.Now()
|
t.Start = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,13 +219,13 @@ func (s *service) Retry(ctx context.Context, req *RetryReq) (*rest.EmptyResp, er
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("step %s not found", req.StepName)
|
return nil, fmt.Errorf("step %s not found", req.StepName)
|
||||||
}
|
}
|
||||||
if step.Status == itypes.TaskStatusSuccess {
|
if step.Status == types.TaskStatusSuccess {
|
||||||
return nil, fmt.Errorf("step %s already success", req.StepName)
|
return nil, fmt.Errorf("step %s already success", req.StepName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if step.Status == itypes.TaskStatusFailure {
|
if step.Status == types.TaskStatusFailure {
|
||||||
step.RetryCount = 0
|
step.RetryCount = 0
|
||||||
step.Status = itypes.TaskStatusNotStarted
|
step.Status = types.TaskStatusNotStarted
|
||||||
}
|
}
|
||||||
t.SetCurrentStep(req.StepName)
|
t.SetCurrentStep(req.StepName)
|
||||||
if err := s.mgr.RetryAt(t, req.StepName); err != nil {
|
if err := s.mgr.RetryAt(t, req.StepName); err != nil {
|
||||||
|
|
@ -235,8 +235,8 @@ func (s *service) Retry(ctx context.Context, req *RetryReq) (*rest.EmptyResp, er
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全量重试必须有失败的任务
|
// 全量重试必须有失败的任务
|
||||||
notSuccessStep := lo.Filter(t.Steps, func(v *itypes.Step, _ int) bool {
|
notSuccessStep := lo.Filter(t.Steps, func(v *types.Step, _ int) bool {
|
||||||
return v.Status != itypes.TaskStatusSuccess
|
return v.Status != types.TaskStatusSuccess
|
||||||
})
|
})
|
||||||
if len(notSuccessStep) == 0 {
|
if len(notSuccessStep) == 0 {
|
||||||
return nil, fmt.Errorf("task %s all step already success", req.TaskID)
|
return nil, fmt.Errorf("task %s all step already success", req.TaskID)
|
||||||
|
|
@ -244,9 +244,9 @@ func (s *service) Retry(ctx context.Context, req *RetryReq) (*rest.EmptyResp, er
|
||||||
|
|
||||||
// 错误步骤重试次数置为0, 只当前步骤有效
|
// 错误步骤重试次数置为0, 只当前步骤有效
|
||||||
for _, step := range t.Steps {
|
for _, step := range t.Steps {
|
||||||
if step.Status == itypes.TaskStatusFailure {
|
if step.Status == types.TaskStatusFailure {
|
||||||
step.RetryCount = 0
|
step.RetryCount = 0
|
||||||
step.Status = itypes.TaskStatusNotStarted
|
step.Status = types.TaskStatusNotStarted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 任务级重试
|
// 任务级重试
|
||||||
|
|
@ -284,7 +284,7 @@ func (s *service) Revoke(ctx context.Context, req *commonReq) (*rest.EmptyResp,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if t.Status != itypes.TaskStatusRunning {
|
if t.Status != types.TaskStatusRunning {
|
||||||
return nil, fmt.Errorf("task %s not running", req.TaskID)
|
return nil, fmt.Errorf("task %s not running", req.TaskID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,7 +317,7 @@ func (s *service) Status(ctx context.Context, req *commonReq) (*Task, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
steps := lo.Map(taskData.Steps, func(v *itypes.Step, _ int) *Step {
|
steps := lo.Map(taskData.Steps, func(v *types.Step, _ int) *Step {
|
||||||
return &Step{
|
return &Step{
|
||||||
Step: v,
|
Step: v,
|
||||||
ExecutionDuration: (time.Duration(v.ExecutionTime) * time.Millisecond).String(),
|
ExecutionDuration: (time.Duration(v.ExecutionTime) * time.Millisecond).String(),
|
||||||
|
|
@ -401,7 +401,7 @@ func (s *service) List(ctx context.Context, req *ListReq) (*rest.PaginationResp[
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
items := lo.Map(result.Items, func(v *itypes.Task, _ int) Task {
|
items := lo.Map(result.Items, func(v *types.Task, _ int) Task {
|
||||||
return Task{
|
return Task{
|
||||||
Task: v,
|
Task: v,
|
||||||
ExecutionDuration: (time.Duration(v.ExecutionTime) * time.Millisecond).String(),
|
ExecutionDuration: (time.Duration(v.ExecutionTime) * time.Millisecond).String(),
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func (s *State) isReadyToStep(stepName string) (*types.Step, error) {
|
||||||
SetExecutionTime(taskStartTime, nowTime).
|
SetExecutionTime(taskStartTime, nowTime).
|
||||||
SetStatus(types.TaskStatusFailure).
|
SetStatus(types.TaskStatusFailure).
|
||||||
SetMessage(failMsg)
|
SetMessage(failMsg)
|
||||||
return nil, fmt.Errorf(failMsg)
|
return nil, fmt.Errorf("%s", failMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if curStep.GetSkipOnFailed() {
|
if curStep.GetSkipOnFailed() {
|
||||||
|
|
@ -166,7 +166,7 @@ func (s *State) isReadyToStep(stepName string) (*types.Step, error) {
|
||||||
SetExecutionTime(taskStartTime, nowTime).
|
SetExecutionTime(taskStartTime, nowTime).
|
||||||
SetStatus(types.TaskStatusFailure).
|
SetStatus(types.TaskStatusFailure).
|
||||||
SetMessage(failMsg)
|
SetMessage(failMsg)
|
||||||
return nil, fmt.Errorf(failMsg)
|
return nil, fmt.Errorf("%s", failMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// not first time to execute current step
|
// not first time to execute current step
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue