worker

package
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWorkerPoolJobQueueIsFull WorkerPool JobQueue Is Full
	ErrWorkerPoolJobQueueIsFull = errors.New("workerPool JobQueue is full")
	// ErrWorkerPoolIsClosed WorkerPool Is Closed
	ErrWorkerPoolIsClosed = errors.New("workerPool is closed")
	// ErrWorkerPoolScheduleTimeout WorkerPool Schedule Timeout
	ErrWorkerPoolScheduleTimeout = errors.New("workerPool schedule timeout")
)

Functions

This section is empty.

Types

type DefaultInvokable

type DefaultInvokable[T any] struct {
	// contains filtered or unexported fields
}

DefaultInvokable DefaultInvokable inspired by Java ExecutorService

func NewDefaultInvokable

func NewDefaultInvokable[T any](workerPool WorkerPool, callee func(T)) *DefaultInvokable[T]

NewDefaultInvokable New a DefaultInvokable on the workerPool

func (*DefaultInvokable[T]) Invoke

func (invokableSelf *DefaultInvokable[T]) Invoke(val T)

Invoke Invoke the job (non-blocking)

func (*DefaultInvokable[T]) InvokeWithTimeout

func (invokableSelf *DefaultInvokable[T]) InvokeWithTimeout(val T, timeout time.Duration) error

InvokeWithTimeout Invoke the job with timeout (blocking, by workerPool.ScheduleWithTimeout())

func (*DefaultInvokable[T]) SetCallee

func (invokableSelf *DefaultInvokable[T]) SetCallee(callee func(T)) *DefaultInvokable[T]

SetCallee Set the Callee

func (*DefaultInvokable[T]) SetWorkerPool

func (invokableSelf *DefaultInvokable[T]) SetWorkerPool(workerPool WorkerPool) *DefaultInvokable[T]

SetWorkerPool Set the WorkerPool

type DefaultWorkerPool

type DefaultWorkerPool struct {

	// Settings
	DefaultWorkerPoolSettings
	// contains filtered or unexported fields
}

DefaultWorkerPool DefaultWorkerPool inspired by Java ExecutorService

func NewDefaultWorkerPool

func NewDefaultWorkerPool(jobQueue *fpgo.BufferedChannelQueue[func()], settings *DefaultWorkerPoolSettings) *DefaultWorkerPool

NewDefaultWorkerPool New a DefaultWorkerPool

func (*DefaultWorkerPool) Close

func (workerPoolSelf *DefaultWorkerPool) Close()

Close Close the DefaultWorkerPool

func (*DefaultWorkerPool) IsClosed

func (workerPoolSelf *DefaultWorkerPool) IsClosed() bool

IsClosed Is the DefaultWorkerPool closed

func (*DefaultWorkerPool) PreAllocWorkerSize

func (workerPoolSelf *DefaultWorkerPool) PreAllocWorkerSize(preAllocWorkerSize int)

PreAllocWorkerSize PreAllocate Workers

func (*DefaultWorkerPool) Schedule

func (workerPoolSelf *DefaultWorkerPool) Schedule(fn func()) error

Schedule Schedule the Job

func (*DefaultWorkerPool) ScheduleWithTimeout

func (workerPoolSelf *DefaultWorkerPool) ScheduleWithTimeout(fn func(), timeout time.Duration) error

ScheduleWithTimeout Schedule the Job with timeout

func (*DefaultWorkerPool) SetDefaultWorkerPoolSettings

func (workerPoolSelf *DefaultWorkerPool) SetDefaultWorkerPoolSettings(defaultWorkerPoolSettings DefaultWorkerPoolSettings) *DefaultWorkerPool

SetDefaultWorkerPoolSettings Set the defaultWorkerPoolSettings

func (*DefaultWorkerPool) SetIsJobQueueClosedWhenClose

func (workerPoolSelf *DefaultWorkerPool) SetIsJobQueueClosedWhenClose(isJobQueueClosedWhenClose bool) *DefaultWorkerPool

SetIsJobQueueClosedWhenClose Set is the JobQueue closed when the WorkerPool.Close()

func (*DefaultWorkerPool) SetJobQueue

func (workerPoolSelf *DefaultWorkerPool) SetJobQueue(jobQueue *fpgo.BufferedChannelQueue[func()]) *DefaultWorkerPool

SetJobQueue Set the JobQueue(WARNING: if the pool has started to use, doing this is not safe)

func (*DefaultWorkerPool) SetPanicHandler

func (workerPoolSelf *DefaultWorkerPool) SetPanicHandler(panicHandler func(interface{})) *DefaultWorkerPool

SetPanicHandler Set the panicHandler(handle/log panic inside workers)

func (*DefaultWorkerPool) SetScheduleRetryInterval

func (workerPoolSelf *DefaultWorkerPool) SetScheduleRetryInterval(scheduleRetryInterval time.Duration) *DefaultWorkerPool

SetScheduleRetryInterval Retry interval for ScheduleWithTimeout

func (*DefaultWorkerPool) SetSpawnWorkerDuration

func (workerPoolSelf *DefaultWorkerPool) SetSpawnWorkerDuration(spawnWorkerDuration time.Duration) *DefaultWorkerPool

SetSpawnWorkerDuration Set the spawnWorkerDuration(Checking repeating by the interval/duration)

func (*DefaultWorkerPool) SetWorkerBatchSize

func (workerPoolSelf *DefaultWorkerPool) SetWorkerBatchSize(workerBatchSize int) *DefaultWorkerPool

SetWorkerBatchSize Set the workerBatchSize(queued jobs number that every worker could have)

func (*DefaultWorkerPool) SetWorkerExpiryDuration

func (workerPoolSelf *DefaultWorkerPool) SetWorkerExpiryDuration(workerExpiryDuration time.Duration) *DefaultWorkerPool

SetWorkerExpiryDuration The worker would be dead if the worker is idle without jobs over the duration

func (*DefaultWorkerPool) SetWorkerJamDuration

func (workerPoolSelf *DefaultWorkerPool) SetWorkerJamDuration(workerJamDuration time.Duration) *DefaultWorkerPool

SetWorkerJamDuration A new worker would be created if there's no available worker to do jobs over the duration

func (*DefaultWorkerPool) SetWorkerSizeMaximum

func (workerPoolSelf *DefaultWorkerPool) SetWorkerSizeMaximum(workerSizeMaximum int) *DefaultWorkerPool

SetWorkerSizeMaximum Set the workerSizeMaximum

func (*DefaultWorkerPool) SetWorkerSizeStandBy

func (workerPoolSelf *DefaultWorkerPool) SetWorkerSizeStandBy(workerSizeStandBy int) *DefaultWorkerPool

SetWorkerSizeStandBy Set the workerSizeStandBy

type DefaultWorkerPoolSettings

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

DefaultWorkerPoolSettings Settings for DefaultWorkerPool

type Invokable

type Invokable[T any] interface {
	Invoke(val T)
	InvokeWithTimeout(val T, timeout time.Duration) error
}

Invokable Invokable inspired by Java ExecutorService

type WorkerPool

type WorkerPool interface {
	Close()
	IsClosed() bool

	Schedule(func()) error
	ScheduleWithTimeout(func(), time.Duration) error
}

WorkerPool WorkerPool inspired by Java ExecutorService

Jump to

Keyboard shortcuts

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