task

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StatusRunning = iota + 10000
	StatusDone
	StatusError
	StatusPending
	StatusStopped
)
View Source
const (
	StatusTextPending = "Pending"
	StatusTextRunning = "Running"
	StatusTextDone    = "Done"
	StatusTextError   = "Error"
	StatusTextStopped = "Stopped"
)

Canonical status strings used by Template JSON.

Variables

View Source
var (
	SignalDone = Signal("init")
)

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) MarkStopped

func (t *BaseTask) MarkStopped()

MarkStopped sets status to Stopped and records end time.

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)

SerializerTemplate serializes a single task for detail APIs, expanding only the direct children (one level).

func (*TaskModule) SerializerTemplateList

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

SerializerTemplateList serializes root tasks for list APIs. Nested subtasks are summarized with hasSubTask/subTaskCount, never expanded.

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"`
	HasSubTask   bool        `json:"hasSubTask"`
	SubTaskCount int         `json:"subTaskCount"`
	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