tasks

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 7 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 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, 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) 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
	// contains filtered or unexported fields
}

TaskManager allows you to create tasks and run them

func New

func New() *TaskManager

New 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, 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

Jump to

Keyboard shortcuts

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