engine

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 17 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 Key] struct {
	WorkerCount uint
}

func (*Config[KEY]) NewEngine

func (c *Config[KEY]) NewEngine() *Engine[KEY]

type Engine

type Engine[KEY Key] struct {
	EngineStatistics
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine[KEY Key](workerCount uint) *Engine[KEY]

func NewEngineWithContext

func NewEngineWithContext[KEY Key](workerCount uint, ctx context.Context) *Engine[KEY]

func (*Engine[KEY]) AddFixedTasks

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

func (*Engine[KEY]) AddNoPriorityTasks

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

func (*Engine[KEY]) AddTasks

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

func (*Engine[KEY]) AddWorker

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

func (*Engine[KEY]) AsyncAddTasks

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

func (*Engine[KEY]) Cancel

func (e *Engine[KEY]) Cancel()

func (*Engine[KEY]) CancelAfter

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

func (*Engine[KEY]) Context

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

func (*Engine[KEY]) ErrHandler

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

func (*Engine[KEY]) ErrHandlerRetryTimes

func (e *Engine[KEY]) ErrHandlerRetryTimes(times int) *Engine[KEY]

func (*Engine[KEY]) ErrHandlerUtilSuccess

func (e *Engine[KEY]) ErrHandlerUtilSuccess() *Engine[KEY]

func (*Engine[KEY]) ErrHandlerWriteToFile

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

func (*Engine[KEY]) ExecTask

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

func (*Engine[KEY]) KindGroupRandSpeedLimit

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

func (*Engine[KEY]) KindGroupSpeedLimit

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

多个kind共用一个timer

func (*Engine[KEY]) KindLimiter

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

func (*Engine[KEY]) KindRandSpeedLimit

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

func (*Engine[KEY]) KindSpeedLimit

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

func (*Engine[KEY]) Limiter

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

func (*Engine[KEY]) MonitorInterval

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

func (*Engine[KEY]) NewFixedWorker

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

func (*Engine[KEY]) RandSpeedLimited

func (e *Engine[KEY]) RandSpeedLimited(minInterval, maxInterval time.Duration) *Engine[KEY]

func (*Engine[KEY]) Run

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

func (*Engine[KEY]) RunSingleWorker

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

func (*Engine[KEY]) SkipKind

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

func (*Engine[KEY]) SpeedLimited

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

func (*Engine[KEY]) Stop

func (e *Engine[KEY]) Stop()

func (*Engine[KEY]) StopAfter

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

func (*Engine[KEY]) StopCallBack

func (e *Engine[KEY]) StopCallBack(callBack func()) *Engine[KEY]

func (*Engine[KEY]) TaskSourceChannel

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

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

func (*Engine[KEY]) TaskSourceFunc

func (e *Engine[KEY]) TaskSourceFunc(taskSourceFunc func(*Engine[KEY]))

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

type EngineStatistics

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

EngineStatistics 基本引擎统计数据

type ErrHandle

type ErrHandle func(context.Context, error)

type Key added in v1.0.10

type Key interface {
	uint64 | string | byte | int | int32 | uint32 | int64
}

目前受限于ristretto.Cache的泛型限制,考虑移除并引入lru或boolong filter

type Kind

type Kind uint8

type KindHandler

type KindHandler[KEY Key] struct {
	Skip bool

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

type Task

type Task[KEY Key] struct {
	TaskMeta[KEY]
	TaskFunc[KEY]
	// contains filtered or unexported fields
}

func (*Task[KEY]) Errs

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

func (*Task[KEY]) SetContext added in v1.1.0

func (t *Task[KEY]) SetContext(ctx context.Context)

type TaskFunc

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

func (TaskFunc[KEY]) Do

func (t TaskFunc[KEY]) Do(ctx context.Context) ([]*Task[KEY], error)

type TaskInterface

type TaskInterface[KEY Key] interface {
	Do(ctx context.Context) ([]*Task[KEY], error)
}

type TaskMeta

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

	TaskStatistics
	// contains filtered or unexported fields
}

func (*TaskMeta[KEY]) Id

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

func (*TaskMeta[KEY]) SetKey

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

func (*TaskMeta[KEY]) SetKind

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

func (*TaskMeta[KEY]) SetPriority

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

func (*TaskMeta[KEY]) SortKey added in v1.7.0

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

type TaskStatistics

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

type Tasks

type Tasks[KEY Key] []*Task[KEY]

func (Tasks[KEY]) Less

func (tasks Tasks[KEY]) 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 Key] struct {
	Id   uint
	Type Type
	Kind Kind
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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