task

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTaskNotRunning      = errors.New("process is not running")
	ErrTaskInterrupted     = errors.New("process was interrupted")
	ErrUninterruptibleTask = errors.New("unable to cancel uninterruptible process")
)
View Source
var (
	ErrPoolClosed = errors.New("pool is closed")
)

Functions

func IsTaskAlreadyRunningError

func IsTaskAlreadyRunningError(err error) bool

Types

type FuncTask

type FuncTask struct {
	*GenericTask
	// contains filtered or unexported fields
}

func (*FuncTask) GetKey

func (t *FuncTask) GetKey() string

func (*FuncTask) Main

func (t *FuncTask) Main() error

type GenericTask

type GenericTask struct {
	sync.Mutex

	Logger *log.Entry
	// contains filtered or unexported fields
}

It's an implementation of a generic task

func (*GenericTask) BeforeStart

func (t *GenericTask) BeforeStart(a interface{}) error

func (*GenericTask) Cancel

func (t *GenericTask) Cancel() error

func (*GenericTask) Ctx

func (t *GenericTask) Ctx() context.Context

func (*GenericTask) Err

func (t *GenericTask) Err() error

Err returns the last migration error

func (*GenericTask) GetCreationTime

func (t *GenericTask) GetCreationTime() time.Time

func (*GenericTask) GetKey

func (t *GenericTask) GetKey() string

func (*GenericTask) GetModifiedTime

func (t *GenericTask) GetModifiedTime() time.Time

func (*GenericTask) GetNS

func (t *GenericTask) GetNS() string

func (*GenericTask) IsCompleted

func (t *GenericTask) IsCompleted() bool

func (*GenericTask) IsFailed

func (t *GenericTask) IsFailed() bool

func (*GenericTask) IsRunning

func (t *GenericTask) IsRunning() bool

func (*GenericTask) OnFailure

func (t *GenericTask) OnFailure() error

func (*GenericTask) OnSuccess

func (t *GenericTask) OnSuccess() error

func (*GenericTask) SetProgress

func (t *GenericTask) SetProgress(p int32)

func (*GenericTask) Stat

func (t *GenericTask) Stat() *TaskStat

func (*GenericTask) Wait

func (t *GenericTask) Wait()

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(depth int) *Pool

func (*Pool) Cancel

func (p *Pool) Cancel(key string)

func (*Pool) Err

func (p *Pool) Err(key string) error

func (*Pool) List

func (p *Pool) List() []string

func (*Pool) RunFunc

func (p *Pool) RunFunc(ctx context.Context, key string, fn func(*log.Entry) error) (string, error)

func (*Pool) StartTask

func (p *Pool) StartTask(ctx context.Context, t Task, resp interface{}) (string, error)

func (*Pool) Stat

func (p *Pool) Stat(key string) *TaskStat

func (*Pool) Wait

func (p *Pool) Wait(key string)

func (*Pool) WaitAndClosePool

func (p *Pool) WaitAndClosePool()

type Task

type Task interface {
	Main() error

	BeforeStart(interface{}) error
	OnSuccess() error
	OnFailure() error

	Wait()
	Cancel() error
	IsRunning() bool

	Err() error
	Ctx() context.Context

	GetNS() string
	GetKey() string
	GetCreationTime() time.Time
	GetModifiedTime() time.Time

	SetProgress(int32)

	Stat() *TaskStat
}

type TaskAlreadyRunningError

type TaskAlreadyRunningError struct {
	Namespace string
	Key       string
}

func (*TaskAlreadyRunningError) Error

func (e *TaskAlreadyRunningError) Error() string

type TaskStat

type TaskStat struct {
	Key       string      `json:"key"`
	State     TaskState   `json:"state"`
	StateDesc string      `json:"state_desc"`
	Progress  int32       `json:"progress"`
	Details   interface{} `json:"details"`
}

type TaskState

type TaskState int32
const (
	StateUnknown TaskState = iota
	StateRunning
	StateCompleted
	StateFailed
)

Jump to

Keyboard shortcuts

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