gitee.com/h79/goutils@v1.22.10/common/scheduler/task.go (about)

     1  package scheduler
     2  
     3  import "gitee.com/h79/goutils/common/option"
     4  
     5  type Task interface {
     6  	GetId() string
     7  	GetType() string
     8  	GetState() State
     9  	GetStartAt() int64 // new object time
    10  	GetExecAt() int64  // 最近一次执行时间
    11  	GetCount() int64   // 执行次数
    12  	GetPayload() any
    13  	Execute(opts ...option.Option) (any, error)
    14  	Cancel()
    15  	Pause()
    16  	Start()
    17  }
    18  
    19  type State int
    20  
    21  func (s State) Is(ss State) bool {
    22  	return s == ss
    23  }
    24  
    25  func (s State) String() string {
    26  	switch s {
    27  	case InitState:
    28  		return "Init"
    29  	case RunningState:
    30  		return "Running"
    31  	case PauseState:
    32  		return "Pause"
    33  	case CancelState:
    34  		return "Cancel"
    35  	case CompletedState:
    36  		return "Completed"
    37  	case TimeoutState:
    38  		return "Timeout"
    39  	case ErrorState:
    40  		return "Error"
    41  	}
    42  	return ""
    43  }
    44  
    45  func (s State) IsQuit() bool {
    46  	return s != RunningState && s != InitState && s != PauseState
    47  }
    48  
    49  const (
    50  	InitState      = State(0)
    51  	RunningState   = State(1)
    52  	PauseState     = State(2)
    53  	CancelState    = State(3)
    54  	CompletedState = State(4)
    55  	TimeoutState   = State(5)
    56  	ErrorState     = State(6)
    57  )