task

package
v0.0.0-...-35b844d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusRunning = iota + 10000
	StatusDone
	StatusError
)

Variables

View Source
var (
	SignalDone = Signal("init")
)
View Source
var StatusNameMapping map[int]string = map[int]string{
	StatusRunning: "Running",
	StatusDone:    "Done",
	StatusError:   "Error",
}

Functions

func GetStatusText

func GetStatusText(extraMapping map[int]string, status int) string

func RunTask

func RunTask(wrap Wrap) error

Types

type BaseTask

type BaseTask struct {
	Id           string
	Type         string
	Status       string
	Owner        string
	Err          error
	OnDone       chan Signal
	Created      time.Time
	SubTaskList  []Task
	StartTime    time.Time
	EndTime      time.Time
	ParentTaskId string
}

func NewBaseTask

func NewBaseTask(Type string, owner string, status string) *BaseTask

func NewSubTask

func NewSubTask(Type string, owner string, status string, parentId string) *BaseTask

func (*BaseTask) AbortError

func (t *BaseTask) AbortError(err error) error

func (*BaseTask) Done

func (t *BaseTask) Done()

func (*BaseTask) Error

func (t *BaseTask) Error() error

func (*BaseTask) GetCreated

func (t *BaseTask) GetCreated() time.Time

func (*BaseTask) GetEndTime

func (t *BaseTask) GetEndTime() time.Time

func (*BaseTask) GetId

func (t *BaseTask) GetId() string

func (*BaseTask) GetParentTaskId

func (t *BaseTask) GetParentTaskId() string

func (*BaseTask) GetStartTime

func (t *BaseTask) GetStartTime() time.Time

func (*BaseTask) GetStatus

func (t *BaseTask) GetStatus() string

func (*BaseTask) GetType

func (t *BaseTask) GetType() string

func (*BaseTask) SetEnd

func (t *BaseTask) SetEnd()

func (*BaseTask) SetStart

func (t *BaseTask) SetStart()

func (*BaseTask) SubTask

func (t *BaseTask) SubTask() []Task

type Signal

type Signal string

type Task

type Task interface {
	GetId() string
	GetType() string
	GetStatus() string
	Stop() error
	Start() error
	Error() error
	GetCreated() time.Time
	Output() (interface{}, error)
	SubTask() []Task
	GetStartTime() time.Time
	GetEndTime() time.Time
	GetParentTaskId() string
}

type TaskModule

type TaskModule struct {
	Pool               *TaskPool
	Converter          []interface{}
	ListHandler        haruka.RequestHandler
	GetTaskByIdHandler haruka.RequestHandler
	ErrorHandler       func(context *haruka.Context, err error)
}

func NewTaskModule

func NewTaskModule() *TaskModule

func (*TaskModule) AddConverter

func (t *TaskModule) AddConverter(converters ...interface{})

func (*TaskModule) SerializerTemplate

func (t *TaskModule) SerializerTemplate(data Task) (interface{}, error)

func (*TaskModule) SerializerTemplateList

func (t *TaskModule) SerializerTemplateList() (interface{}, error)

func (*TaskModule) SerializerTemplateOutput

func (t *TaskModule) SerializerTemplateOutput(data interface{}) (interface{}, error)

type TaskPool

type TaskPool struct {
	sync.Mutex
	Tasks []Task
}

func NewTaskPool

func NewTaskPool() *TaskPool

func (*TaskPool) AddTask

func (p *TaskPool) AddTask(task Task)

func (*TaskPool) GetTaskById

func (p *TaskPool) GetTaskById(id string) Task

func (*TaskPool) GetTaskWithStatus

func (p *TaskPool) GetTaskWithStatus(taskType string, status string) Task

func (*TaskPool) RemoveTaskById

func (p *TaskPool) RemoveTaskById(id string)

type Template

type Template struct {
	Id           string      `json:"id"`
	Type         string      `json:"type"`
	Status       string      `json:"status"`
	Created      string      `json:"created"`
	Err          string      `json:"err,omitempty"`
	Output       interface{} `json:"output,omitempty"`
	SubTask      []*Template `json:"subTask,omitempty"`
	StartTime    string      `json:"startTime,omitempty"`
	EndTime      string      `json:"endTime,omitempty"`
	Duration     uint        `json:"duration,omitempty"`
	ParentTaskId string      `json:"parentTaskId,omitempty"`
}

type Wrap

type Wrap interface {
	SetStart()
	SetEnd()
	AbortError(err error) error
	Done()
	Start() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL