conctrl

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindNormal = iota
)

Variables

This section is empty.

Functions

func ReTry

func ReTry(times int, f func() error) error

Types

type BaseEngine

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

func NewBaseEngine

func NewBaseEngine[KEY comparable, T, W any](workerCount uint) *BaseEngine[KEY, T, W]

func NewBaseEngineWithContext

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

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

func (e *BaseEngine[KEY, T, W]) AddFixedTask(workerId int, task *BaseTask[KEY, T]) error

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

func (e *BaseEngine[KEY, T, W]) AddTask(task *BaseTask[KEY, T])

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

func (e *BaseEngine[KEY, T, W]) AddTasks(tasks ...*BaseTask[KEY, T])

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

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

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

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

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

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

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

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

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

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

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

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

func (*BaseEngine[KEY, T, W]) Release

func (e *BaseEngine[KEY, T, W]) Release()

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

func (e *BaseEngine[KEY, T, W]) Run(tasks ...*BaseTask[KEY, T])

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

func (e *BaseEngine[KEY, T, W]) RunSingleWorker(tasks ...*BaseTask[KEY, T])

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

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

func (*BaseEngine[KEY, T, W]) SyncRun

func (e *BaseEngine[KEY, T, W]) SyncRun(tasks ...*BaseTask[KEY, T])

type BaseEngineStatistics added in v1.1.0

type BaseEngineStatistics = WorkStatistics

BaseEngineStatistics 基本引擎统计数据

type BaseTask

type BaseTask[KEY comparable, T any] struct {
	BaseTaskMeta[KEY]
	BaseTaskFunc
	Props T
}

type BaseTaskFunc

type BaseTaskFunc func(context.Context)

type BaseTaskMeta

type BaseTaskMeta[KEY comparable] struct {
	Key      KEY
	Describe string
	Priority int
	// contains filtered or unexported fields
}

func (*BaseTaskMeta[KEY]) OrderKey added in v1.1.0

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

func (*BaseTaskMeta[KEY]) SetPriority

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

type Controller

type Controller chan func() error

func (Controller) AddTask

func (c Controller) AddTask(f func() error)

func (Controller) Start

func (c Controller) Start()

type Engine

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

func NewEngine

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

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

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

func (*Engine[KEY, T, W]) AddNoPriorityTask added in v1.1.0

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

func (*Engine[KEY, T, W]) AddNoPriorityTasks added in v1.1.0

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

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

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

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

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 added in v1.1.0

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

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

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

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

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

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]) SourceTask added in v1.1.0

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

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]) TaskSource added in v1.1.0

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

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

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 {
	// contains filtered or unexported fields
}

引擎统计数据

type ErrHandle

type ErrHandle func(context.Context, error)

type Kind

type Kind uint8

type KindConfig

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

type KindEngine

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

TODO

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

func (e *KindEngine[KEY, T, W]) Run()

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 AnonymousTask

func AnonymousTask[KEY comparable, T any](fun BaseTaskFunc) *Task[KEY, T]

func NewTask

func NewTask[KEY comparable, T any](baseTask *BaseTask[KEY, T]) *Task[KEY, T]

func (*Task[KEY, P]) BaseTask

func (t *Task[KEY, P]) BaseTask(handle func(tasks []*Task[KEY, P], err error)) *BaseTask[KEY, P]

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 {
	BaseTaskMeta[KEY]
	Kind Kind
	TaskStatistics
}

TODO

func (*TaskMeta[KEY]) Id

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

func (*TaskMeta[KEY]) SetKey

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

func (*TaskMeta[KEY]) SetKind

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

type TaskStatistics

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

type Tasks

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

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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