task

package
v3.34.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package task manage task, such as file upload, file copy between storages, offline download, etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskNotFound = errors.New("task not found")
	ErrTaskRunning  = errors.New("task is running")
)
View Source
var (
	PENDING   = "pending"
	RUNNING   = "running"
	SUCCEEDED = "succeeded"
	CANCELING = "canceling"
	CANCELED  = "canceled"
	ERRORED   = "errored"
)

Functions

This section is empty.

Types

type Callback

type Callback[K comparable] func(task *Task[K])

type Func

type Func[K comparable] func(task *Task[K]) error

type Manager

type Manager[K comparable] struct {
	// contains filtered or unexported fields
}

func NewTaskManager

func NewTaskManager[K comparable](maxWorker int, updateID ...func(*K)) *Manager[K]

func (*Manager[K]) Cancel

func (tm *Manager[K]) Cancel(tid K) error

func (*Manager[K]) ClearDone

func (tm *Manager[K]) ClearDone()

func (*Manager[K]) ClearSucceeded added in v3.14.0

func (tm *Manager[K]) ClearSucceeded()

func (*Manager[K]) Get

func (tm *Manager[K]) Get(tid K) (*Task[K], bool)

func (*Manager[K]) GetAll

func (tm *Manager[K]) GetAll() []*Task[K]

func (*Manager[K]) GetByStates

func (tm *Manager[K]) GetByStates(states ...string) []*Task[K]

func (*Manager[K]) ListDone

func (tm *Manager[K]) ListDone() []*Task[K]

func (*Manager[K]) ListUndone

func (tm *Manager[K]) ListUndone() []*Task[K]

func (*Manager[K]) MustGet

func (tm *Manager[K]) MustGet(tid K) *Task[K]

func (*Manager[K]) RawTasks

func (tm *Manager[K]) RawTasks() *generic_sync.MapOf[K, *Task[K]]

func (*Manager[K]) Remove

func (tm *Manager[K]) Remove(tid K) error

func (*Manager[K]) RemoveAll

func (tm *Manager[K]) RemoveAll()

RemoveAll removes all tasks from the manager, this maybe shouldn't be used because the task maybe still running.

func (*Manager[K]) RemoveByStates

func (tm *Manager[K]) RemoveByStates(states ...string)

func (*Manager[K]) Retry

func (tm *Manager[K]) Retry(tid K) error

func (*Manager[K]) Submit

func (tm *Manager[K]) Submit(task *Task[K]) K

type Task

type Task[K comparable] struct {
	ID   K
	Name string

	Error error

	Func Func[K]

	Ctx context.Context
	// contains filtered or unexported fields
}

func WithCancelCtx

func WithCancelCtx[K comparable](task *Task[K]) *Task[K]

func (*Task[K]) Cancel

func (t *Task[K]) Cancel()

func (*Task[K]) Done

func (t *Task[K]) Done() bool

func (Task[K]) GetErrMsg

func (t Task[K]) GetErrMsg() string

func (Task[K]) GetProgress

func (t Task[K]) GetProgress() float64

func (Task[K]) GetState

func (t Task[K]) GetState() string

func (Task[K]) GetStatus

func (t Task[K]) GetStatus() string

func (*Task[K]) SetProgress

func (t *Task[K]) SetProgress(percentage float64)

func (*Task[K]) SetStatus

func (t *Task[K]) SetStatus(status string)

Jump to

Keyboard shortcuts

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