tasks

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTaskNotFound = errors.New("task not found")

ErrTaskNotFound is returned when a task is not found

Functions

This section is empty.

Types

type TaskEvent added in v0.24.2

type TaskEvent struct {
	Name  string                 `json:"name"`
	State TaskState              `json:"state"`
	Meta  map[string]interface{} `json:"meta"`
}

func NewTaskEvent added in v0.24.2

func NewTaskEvent(item *TaskItem, state TaskState) *TaskEvent

func (*TaskEvent) String added in v0.24.2

func (e *TaskEvent) String() string

String returns the string representation of the task event

type TaskFunc

type TaskFunc func(ctx context.Context) error

TaskFunc is the function type of the task to run

type TaskItem

type TaskItem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TaskItem is the task item stored in the TaskManager

func NewTaskItem

func NewTaskItem(name string, meta map[string]interface{}, tf TaskFunc) *TaskItem

NewTaskItem creates a new task item

func (*TaskItem) Cancel

func (t *TaskItem) Cancel()

Cancel cancels the task

func (*TaskItem) Run

func (t *TaskItem) Run(ctx context.Context) error

Run runs the task once TODO: add error handling

func (*TaskItem) UpdateMeta added in v0.24.2

func (t *TaskItem) UpdateMeta(meta map[string]interface{})

UpdateMeta updates the meta data of the task

func (*TaskItem) Watch

func (t *TaskItem) Watch(ctx context.Context, dependencies ...string)

Watch watches all the dependencies of the task and runs the task it uses fsnotify to watch the files

type TaskManager

type TaskManager struct {
	sync.RWMutex

	*helper.EventEmitter[*TaskEvent]
	// contains filtered or unexported fields
}

TaskManager allows you to create tasks and run them

func NewTaskManager added in v0.24.2

func NewTaskManager() *TaskManager

NewTaskManager creates a new task manager

func (*TaskManager) AddTask

func (tm *TaskManager) AddTask(task *TaskItem)

AddTask adds a task to the task manager

func (*TaskManager) Cancel

func (tm *TaskManager) Cancel(name string) error

Cancel cancels a task

func (*TaskManager) CancelAll

func (tm *TaskManager) CancelAll()

CancelAll cancels all the tasks

func (*TaskManager) Get

func (tm *TaskManager) Get(name string) *TaskItem

Get returns a task

func (*TaskManager) Has

func (tm *TaskManager) Has(name string) bool

Has returns true if the task exists

func (*TaskManager) Names

func (tm *TaskManager) Names() []string

Names returns the names of all the tasks

func (*TaskManager) Register

func (tm *TaskManager) Register(name string, meta map[string]interface{}, tf TaskFunc) *TaskItem

Register creates a new task

func (*TaskManager) RmTask

func (tm *TaskManager) RmTask(name string) error

RmTask removes a task from the task manager

func (*TaskManager) Run

func (tm *TaskManager) Run(ctx context.Context, name string) error

Run runs a task

func (*TaskManager) Watch

func (tm *TaskManager) Watch(ctx context.Context, name string, dependencies ...string) error

Watch watches a task

type TaskState added in v0.24.2

type TaskState int
const (
	// TaskStateIdle is the state when a task is idle
	TaskStateIdle TaskState = iota
	// TaskStateAdded is the state when a task is added
	TaskStateAdded
	// TaskStateRemoved is the state when a task is removed
	TaskStateRemoved
	// TaskStateWatching is the state when a task is watching
	TaskStateWatching
	// TaskStateRunning is the state when a task is running
	TaskStateRunning
	// TaskStateFinished is the state when a task is finished
	TaskStateFinished
	// TaskStateStopped is the state when a task is stopped
	TaskStateStopped
	// TaskStateFailed is the state when a task is failed
	TaskStateFailed
)

func (TaskState) String added in v0.24.2

func (s TaskState) String() string

String returns the string representation of the task state

Jump to

Keyboard shortcuts

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