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