engine

package
v0.0.0-...-f5948c0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindNormal = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config[KEY comparable, T, W any] struct {
	WorkerCount uint
}

func (*Config[KEY, T, W]) NewEngine

func (c *Config[KEY, T, W]) NewEngine() *Engine[KEY, T, W]

type Engine

type Engine[KEY comparable, T, W any] struct {
	EngineStatistics
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine[KEY comparable, T, W any](workerCount uint) *Engine[KEY, T, W]

func NewEngineWithContext

func NewEngineWithContext[KEY comparable, T, W any](workerCount uint, ctx context.Context) *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) AddFixedTask

func (e *Engine[KEY, T, W]) AddFixedTask(workerId int, generation int, task *Task[KEY, T]) error

func (*Engine[KEY, T, W]) AddNoPriorityTask

func (e *Engine[KEY, T, W]) AddNoPriorityTask(task *Task[KEY, T])

func (*Engine[KEY, T, W]) AddNoPriorityTasks

func (e *Engine[KEY, T, W]) AddNoPriorityTasks(tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) AddTask

func (e *Engine[KEY, T, W]) AddTask(generation int, task *Task[KEY, T])

func (*Engine[KEY, T, W]) AddTasks

func (e *Engine[KEY, T, W]) AddTasks(generation int, tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) AddWorker

func (e *Engine[KEY, T, W]) AddWorker(num int)

func (*Engine[KEY, T, W]) AsyncAddTask

func (e *Engine[KEY, T, W]) AsyncAddTask(generation int, tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) Cancel

func (e *Engine[KEY, T, W]) Cancel()

func (*Engine[KEY, T, W]) Context

func (e *Engine[KEY, T, W]) Context() context.Context

func (*Engine[KEY, T, W]) ErrHandler

func (e *Engine[KEY, T, W]) ErrHandler(errHandler func(task *Task[KEY, T])) *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) ErrHandlerUtilSuccess

func (e *Engine[KEY, T, W]) ErrHandlerUtilSuccess() *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) ExecTask

func (e *Engine[KEY, T, W]) ExecTask(ctx context.Context, task *Task[KEY, T])

func (*Engine[KEY, T, W]) KindGroupTimer

func (e *Engine[KEY, T, W]) KindGroupTimer(interval time.Duration, kinds ...Kind) *Engine[KEY, T, W]

多个kind共用一个timer

func (*Engine[KEY, T, W]) Limiter

func (e *Engine[KEY, T, W]) Limiter(kind Kind, r rate.Limit, b int) *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) MonitorInterval

func (e *Engine[KEY, T, W]) MonitorInterval(interval time.Duration)

func (*Engine[KEY, T, W]) NewFixedWorker

func (e *Engine[KEY, T, W]) NewFixedWorker(interval time.Duration) int

func (*Engine[KEY, T, W]) RandSpeedLimited

func (e *Engine[KEY, T, W]) RandSpeedLimited(start, stop time.Duration)

func (*Engine[KEY, T, W]) ReRun

func (e *Engine[KEY, T, W]) ReRun(tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) Run

func (e *Engine[KEY, T, W]) Run(tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) RunSingleWorker

func (e *Engine[KEY, T, W]) RunSingleWorker(tasks ...*Task[KEY, T])

func (*Engine[KEY, T, W]) SkipKind

func (e *Engine[KEY, T, W]) SkipKind(kinds ...Kind) *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) SpeedLimited

func (e *Engine[KEY, T, W]) SpeedLimited(interval time.Duration)

func (*Engine[KEY, T, W]) Stop

func (e *Engine[KEY, T, W]) Stop()

func (*Engine[KEY, T, W]) StopAfter

func (e *Engine[KEY, T, W]) StopAfter(interval time.Duration) *Engine[KEY, T, W]

func (*Engine[KEY, T, W]) TaskSourceChannel

func (e *Engine[KEY, T, W]) TaskSourceChannel(source <-chan *Task[KEY, T])

TaskSourceChannel 任务源,参数是一个channel,channel关闭时,代表任务源停止发送任务

func (*Engine[KEY, T, W]) TaskSourceFunc

func (e *Engine[KEY, T, W]) TaskSourceFunc(task func(*Engine[KEY, T, W]))

TaskSourceFunc,参数为添加任务的函数,直到该函数运行结束,任务引擎才会检测任务是否结束

func (*Engine[KEY, T, W]) Timer

func (e *Engine[KEY, T, W]) Timer(kind Kind, interval time.Duration) *Engine[KEY, T, W]

type EngineStatistics

type EngineStatistics struct {
	WorkStatistics
	// contains filtered or unexported fields
}

EngineStatistics 基本引擎统计数据

type ErrHandle

type ErrHandle func(context.Context, error)

type Kind

type Kind uint8

type KindHandler

type KindHandler[KEY comparable, T any] struct {
	Skip    bool
	Ticker  *time.Ticker
	Limiter *rate.Limiter
	// TODO 指定Kind的Handler
	HandleFun TaskFunc[KEY, T]
}

type Task

type Task[KEY comparable, P any] struct {
	TaskMeta[KEY]
	TaskFunc[KEY, P]

	Props P
	// contains filtered or unexported fields
}

func (*Task[KEY, P]) Errs

func (t *Task[KEY, P]) Errs() []error

type TaskFunc

type TaskFunc[KEY comparable, P any] func(ctx context.Context) ([]*Task[KEY, P], error)

type TaskMeta

type TaskMeta[KEY comparable] struct {
	Key      KEY
	Describe string
	Priority int

	Kind Kind
	TaskStatistics
	// contains filtered or unexported fields
}

TODO

func (*TaskMeta[KEY]) Id

func (r *TaskMeta[KEY]) Id() uint64

func (*TaskMeta[KEY]) OrderKey

func (t *TaskMeta[KEY]) OrderKey() int

func (*TaskMeta[KEY]) SetKey

func (r *TaskMeta[KEY]) SetKey(key KEY)

func (*TaskMeta[KEY]) SetKind

func (r *TaskMeta[KEY]) SetKind(k Kind)

func (*TaskMeta[KEY]) SetPriority

func (t *TaskMeta[KEY]) SetPriority(priority int)

type TaskStatistics

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

type Tasks

type Tasks[KEY comparable, P any] []*Task[KEY, P]

func (Tasks[KEY, T]) Less

func (tasks Tasks[KEY, T]) Less(i, j int) bool

type WorkStatistics

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

WorkStatistics worker统计数据

type Worker

type Worker[KEY comparable, T, W any] struct {
	Id   uint
	Kind Kind

	Props W
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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