engine

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 18 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]) AddFixedTasks

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

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

func (e *Engine[KEY, T, W]) AddNoPriorityTasks(tasks ...*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]) AsyncAddTasks

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

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

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

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

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

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]) ErrHandlerRetryTimes

func (e *Engine[KEY, T, W]) ErrHandlerRetryTimes(times int) *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]) ErrHandlerWriteToFile

func (e *Engine[KEY, T, W]) ErrHandlerWriteToFile(path string) *Engine[KEY, T, W]

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

func (e *Engine[KEY, T, W]) ExecTask(worker *Worker[KEY, T, W], task *Task[KEY, T])

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

func (e *Engine[KEY, T, W]) KindGroupRandSpeedLimit(minInterval, maxInterval time.Duration, kinds ...Kind) *Engine[KEY, T, W]

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

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

多个kind共用一个timer

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

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

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

func (e *Engine[KEY, T, W]) KindRandSpeedLimit(kind Kind, minInterval, maxInterval time.Duration) *Engine[KEY, T, W]

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

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

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

func (e *Engine[KEY, T, W]) Limiter(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(minInterval, maxInterval time.Duration) *Engine[KEY, T, W]

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) *Engine[KEY, T, W]

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]) StopCallBack

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

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

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

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

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

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

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

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

	// TODO 指定Kind的Handler
	HandleFun TaskFunc[KEY, T]
	// contains filtered or unexported fields
}

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 {
	Kind     Kind
	Key      KEY
	Priority int
	Describe string

	TaskStatistics
	// contains filtered or unexported fields
}

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 TaskMetaNew

type TaskMetaNew[T constraints.Key[KEY], KEY comparable] struct{}

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 Type

type Type uint8

type WorkStatistics

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

WorkStatistics worker统计数据

type Worker

type Worker[KEY comparable, T, W any] struct {
	Id   uint
	Type Type
	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