task

package
v1.2.11-prerelease7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package task is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTaskProcessorClosed is the error returned when submiting task to a stopped processor
	ErrTaskProcessorClosed = errors.New("task processor has already shutdown")
)
View Source
var (
	// ErrTaskSchedulerClosed is the error returned when submitting task to a stopped scheduler
	ErrTaskSchedulerClosed = errors.New("task scheduler has already shutdown")
)

Functions

This section is empty.

Types

type FIFOTaskSchedulerOptions added in v0.12.0

type FIFOTaskSchedulerOptions struct {
	QueueSize       int
	WorkerCount     dynamicconfig.IntPropertyFn
	DispatcherCount int
	RetryPolicy     backoff.RetryPolicy
}

FIFOTaskSchedulerOptions configs FIFO task scheduler

func (*FIFOTaskSchedulerOptions) String added in v1.2.7

func (o *FIFOTaskSchedulerOptions) String() string

type MockPriorityTask added in v0.12.0

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

MockPriorityTask is a mock of PriorityTask interface.

func NewMockPriorityTask added in v0.12.0

func NewMockPriorityTask(ctrl *gomock.Controller) *MockPriorityTask

NewMockPriorityTask creates a new mock instance.

func (*MockPriorityTask) Ack added in v0.12.0

func (m *MockPriorityTask) Ack()

Ack mocks base method.

func (*MockPriorityTask) EXPECT added in v0.12.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPriorityTask) Execute added in v0.12.0

func (m *MockPriorityTask) Execute() error

Execute mocks base method.

func (*MockPriorityTask) HandleErr added in v0.12.0

func (m *MockPriorityTask) HandleErr(err error) error

HandleErr mocks base method.

func (*MockPriorityTask) Nack added in v0.12.0

func (m *MockPriorityTask) Nack()

Nack mocks base method.

func (*MockPriorityTask) Priority added in v0.12.0

func (m *MockPriorityTask) Priority() int

Priority mocks base method.

func (*MockPriorityTask) RetryErr added in v0.12.0

func (m *MockPriorityTask) RetryErr(err error) bool

RetryErr mocks base method.

func (*MockPriorityTask) SetPriority added in v0.12.0

func (m *MockPriorityTask) SetPriority(arg0 int)

SetPriority mocks base method.

func (*MockPriorityTask) State added in v0.12.0

func (m *MockPriorityTask) State() State

State mocks base method.

type MockPriorityTaskMockRecorder added in v0.12.0

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

MockPriorityTaskMockRecorder is the mock recorder for MockPriorityTask.

func (*MockPriorityTaskMockRecorder) Ack added in v0.12.0

Ack indicates an expected call of Ack.

func (*MockPriorityTaskMockRecorder) Execute added in v0.12.0

func (mr *MockPriorityTaskMockRecorder) Execute() *gomock.Call

Execute indicates an expected call of Execute.

func (*MockPriorityTaskMockRecorder) HandleErr added in v0.12.0

func (mr *MockPriorityTaskMockRecorder) HandleErr(err interface{}) *gomock.Call

HandleErr indicates an expected call of HandleErr.

func (*MockPriorityTaskMockRecorder) Nack added in v0.12.0

Nack indicates an expected call of Nack.

func (*MockPriorityTaskMockRecorder) Priority added in v0.12.0

func (mr *MockPriorityTaskMockRecorder) Priority() *gomock.Call

Priority indicates an expected call of Priority.

func (*MockPriorityTaskMockRecorder) RetryErr added in v0.12.0

func (mr *MockPriorityTaskMockRecorder) RetryErr(err interface{}) *gomock.Call

RetryErr indicates an expected call of RetryErr.

func (*MockPriorityTaskMockRecorder) SetPriority added in v0.12.0

func (mr *MockPriorityTaskMockRecorder) SetPriority(arg0 interface{}) *gomock.Call

SetPriority indicates an expected call of SetPriority.

func (*MockPriorityTaskMockRecorder) State added in v0.12.0

State indicates an expected call of State.

type MockProcessor added in v0.12.0

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

MockProcessor is a mock of Processor interface.

func NewMockProcessor added in v0.12.0

func NewMockProcessor(ctrl *gomock.Controller) *MockProcessor

NewMockProcessor creates a new mock instance.

func (*MockProcessor) EXPECT added in v0.12.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockProcessor) Start added in v0.12.0

func (m *MockProcessor) Start()

Start mocks base method.

func (*MockProcessor) Stop added in v0.12.0

func (m *MockProcessor) Stop()

Stop mocks base method.

func (*MockProcessor) Submit added in v0.12.0

func (m *MockProcessor) Submit(task Task) error

Submit mocks base method.

type MockProcessorMockRecorder added in v0.12.0

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

MockProcessorMockRecorder is the mock recorder for MockProcessor.

func (*MockProcessorMockRecorder) Start added in v0.12.0

func (mr *MockProcessorMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start.

func (*MockProcessorMockRecorder) Stop added in v0.12.0

Stop indicates an expected call of Stop.

func (*MockProcessorMockRecorder) Submit added in v0.12.0

func (mr *MockProcessorMockRecorder) Submit(task interface{}) *gomock.Call

Submit indicates an expected call of Submit.

type MockScheduler added in v0.12.0

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

MockScheduler is a mock of Scheduler interface.

func NewMockScheduler added in v0.12.0

func NewMockScheduler(ctrl *gomock.Controller) *MockScheduler

NewMockScheduler creates a new mock instance.

func (*MockScheduler) EXPECT added in v0.12.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockScheduler) Start added in v0.12.0

func (m *MockScheduler) Start()

Start mocks base method.

func (*MockScheduler) Stop added in v0.12.0

func (m *MockScheduler) Stop()

Stop mocks base method.

func (*MockScheduler) Submit added in v0.12.0

func (m *MockScheduler) Submit(task PriorityTask) error

Submit mocks base method.

func (*MockScheduler) TrySubmit added in v0.12.0

func (m *MockScheduler) TrySubmit(task PriorityTask) (bool, error)

TrySubmit mocks base method.

type MockSchedulerMockRecorder added in v0.12.0

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

MockSchedulerMockRecorder is the mock recorder for MockScheduler.

func (*MockSchedulerMockRecorder) Start added in v0.12.0

func (mr *MockSchedulerMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start.

func (*MockSchedulerMockRecorder) Stop added in v0.12.0

Stop indicates an expected call of Stop.

func (*MockSchedulerMockRecorder) Submit added in v0.12.0

func (mr *MockSchedulerMockRecorder) Submit(task interface{}) *gomock.Call

Submit indicates an expected call of Submit.

func (*MockSchedulerMockRecorder) TrySubmit added in v0.12.0

func (mr *MockSchedulerMockRecorder) TrySubmit(task interface{}) *gomock.Call

TrySubmit indicates an expected call of TrySubmit.

type MockSequentialTaskQueue added in v0.12.0

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

MockSequentialTaskQueue is a mock of SequentialTaskQueue interface.

func NewMockSequentialTaskQueue added in v0.12.0

func NewMockSequentialTaskQueue(ctrl *gomock.Controller) *MockSequentialTaskQueue

NewMockSequentialTaskQueue creates a new mock instance.

func (*MockSequentialTaskQueue) Add added in v0.12.0

func (m *MockSequentialTaskQueue) Add(task Task)

Add mocks base method.

func (*MockSequentialTaskQueue) EXPECT added in v0.12.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSequentialTaskQueue) IsEmpty added in v0.12.0

func (m *MockSequentialTaskQueue) IsEmpty() bool

IsEmpty mocks base method.

func (*MockSequentialTaskQueue) Len added in v0.12.0

func (m *MockSequentialTaskQueue) Len() int

Len mocks base method.

func (*MockSequentialTaskQueue) QueueID added in v0.12.0

func (m *MockSequentialTaskQueue) QueueID() interface{}

QueueID mocks base method.

func (*MockSequentialTaskQueue) Remove added in v0.12.0

func (m *MockSequentialTaskQueue) Remove() Task

Remove mocks base method.

type MockSequentialTaskQueueMockRecorder added in v0.12.0

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

MockSequentialTaskQueueMockRecorder is the mock recorder for MockSequentialTaskQueue.

func (*MockSequentialTaskQueueMockRecorder) Add added in v0.12.0

func (mr *MockSequentialTaskQueueMockRecorder) Add(task interface{}) *gomock.Call

Add indicates an expected call of Add.

func (*MockSequentialTaskQueueMockRecorder) IsEmpty added in v0.12.0

IsEmpty indicates an expected call of IsEmpty.

func (*MockSequentialTaskQueueMockRecorder) Len added in v0.12.0

Len indicates an expected call of Len.

func (*MockSequentialTaskQueueMockRecorder) QueueID added in v0.12.0

QueueID indicates an expected call of QueueID.

func (*MockSequentialTaskQueueMockRecorder) Remove added in v0.12.0

Remove indicates an expected call of Remove.

type MockTask added in v0.12.0

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

MockTask is a mock of Task interface.

func NewMockTask added in v0.12.0

func NewMockTask(ctrl *gomock.Controller) *MockTask

NewMockTask creates a new mock instance.

func (*MockTask) Ack added in v0.12.0

func (m *MockTask) Ack()

Ack mocks base method.

func (*MockTask) EXPECT added in v0.12.0

func (m *MockTask) EXPECT() *MockTaskMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTask) Execute added in v0.12.0

func (m *MockTask) Execute() error

Execute mocks base method.

func (*MockTask) HandleErr added in v0.12.0

func (m *MockTask) HandleErr(err error) error

HandleErr mocks base method.

func (*MockTask) Nack added in v0.12.0

func (m *MockTask) Nack()

Nack mocks base method.

func (*MockTask) RetryErr added in v0.12.0

func (m *MockTask) RetryErr(err error) bool

RetryErr mocks base method.

func (*MockTask) State added in v0.12.0

func (m *MockTask) State() State

State mocks base method.

type MockTaskMockRecorder added in v0.12.0

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

MockTaskMockRecorder is the mock recorder for MockTask.

func (*MockTaskMockRecorder) Ack added in v0.12.0

func (mr *MockTaskMockRecorder) Ack() *gomock.Call

Ack indicates an expected call of Ack.

func (*MockTaskMockRecorder) Execute added in v0.12.0

func (mr *MockTaskMockRecorder) Execute() *gomock.Call

Execute indicates an expected call of Execute.

func (*MockTaskMockRecorder) HandleErr added in v0.12.0

func (mr *MockTaskMockRecorder) HandleErr(err interface{}) *gomock.Call

HandleErr indicates an expected call of HandleErr.

func (*MockTaskMockRecorder) Nack added in v0.12.0

func (mr *MockTaskMockRecorder) Nack() *gomock.Call

Nack indicates an expected call of Nack.

func (*MockTaskMockRecorder) RetryErr added in v0.12.0

func (mr *MockTaskMockRecorder) RetryErr(err interface{}) *gomock.Call

RetryErr indicates an expected call of RetryErr.

func (*MockTaskMockRecorder) State added in v0.12.0

func (mr *MockTaskMockRecorder) State() *gomock.Call

State indicates an expected call of State.

type ParallelTaskProcessorOptions added in v0.12.0

type ParallelTaskProcessorOptions struct {
	QueueSize   int
	WorkerCount dynamicconfig.IntPropertyFn
	RetryPolicy backoff.RetryPolicy
}

ParallelTaskProcessorOptions configs PriorityTaskProcessor

type PriorityTask added in v0.12.0

type PriorityTask interface {
	Task
	// Priority returns the priority of the task, or noPriority if no priority was previously assigned
	Priority() int
	// SetPriority sets the priority of the task
	SetPriority(int)
}

PriorityTask is the interface for tasks which have and can be assigned a priority

type Processor added in v0.12.0

type Processor interface {
	common.Daemon
	Submit(task Task) error
}

Processor is the generic coroutine pool interface which process tasks

func NewParallelTaskProcessor added in v0.12.0

func NewParallelTaskProcessor(
	logger log.Logger,
	metricsClient metrics.Client,
	options *ParallelTaskProcessorOptions,
) Processor

NewParallelTaskProcessor creates a new PriorityTaskProcessor

func NewSequentialTaskProcessor

func NewSequentialTaskProcessor(
	coroutineSize int,
	taskQueueHashFn collection.HashFunc,
	taskQueueFactory SequentialTaskQueueFactory,
	metricsClient metrics.Client,
	logger log.Logger,
) Processor

NewSequentialTaskProcessor create a new sequential tasks processor

type Scheduler added in v0.12.0

type Scheduler interface {
	common.Daemon
	Submit(task PriorityTask) error
	TrySubmit(task PriorityTask) (bool, error)
}

Scheduler is the generic interface for scheduling tasks with priority and processing them

func NewFIFOTaskScheduler added in v0.12.0

func NewFIFOTaskScheduler(
	logger log.Logger,
	metricsClient metrics.Client,
	options *FIFOTaskSchedulerOptions,
) Scheduler

NewFIFOTaskScheduler creates a new FIFO task scheduler it's an no-op implementation as it simply copy tasks from one task channel to another task channel. This scheduler is only for development purpose.

func NewWeightedRoundRobinTaskScheduler added in v0.12.0

func NewWeightedRoundRobinTaskScheduler(
	logger log.Logger,
	metricsClient metrics.Client,
	options *WeightedRoundRobinTaskSchedulerOptions,
) (Scheduler, error)

NewWeightedRoundRobinTaskScheduler creates a new WRR task scheduler

type SchedulerOptions added in v1.2.7

type SchedulerOptions struct {
	SchedulerType        SchedulerType
	FIFOSchedulerOptions *FIFOTaskSchedulerOptions
	WRRSchedulerOptions  *WeightedRoundRobinTaskSchedulerOptions
}

func NewSchedulerOptions added in v1.2.7

func NewSchedulerOptions(
	schedulerType int,
	queueSize int,
	workerCount dynamicconfig.IntPropertyFn,
	dispatcherCount int,
	weights dynamicconfig.MapPropertyFn,
) (*SchedulerOptions, error)

func (*SchedulerOptions) String added in v1.2.7

func (o *SchedulerOptions) String() string

type SchedulerType added in v0.12.0

type SchedulerType int

SchedulerType respresents the type of the task scheduler implementation

const (
	// SchedulerTypeFIFO is the scheduler type for FIFO scheduler implementation
	SchedulerTypeFIFO SchedulerType = iota + 1
	// SchedulerTypeWRR is the scheduler type for weighted round robin scheduler implementation
	SchedulerTypeWRR
)

type SequentialTaskQueue added in v0.5.8

type SequentialTaskQueue interface {
	// QueueID return the ID of the queue, as well as the tasks inside (same)
	QueueID() interface{}
	// Add push an task to the task set
	Add(task Task)
	// Remove pop an task from the task set
	Remove() Task
	// IsEmpty indicate if the task set is empty
	IsEmpty() bool
	// Len return the size of the queue
	Len() int
}

SequentialTaskQueue is the generic task queue interface which group sequential tasks to be executed one by one

type SequentialTaskQueueFactory added in v0.5.8

type SequentialTaskQueueFactory func(task Task) SequentialTaskQueue

SequentialTaskQueueFactory is the function which generate a new SequentialTaskQueue for a give SequentialTask

type State added in v0.12.0

type State int

State represents the current state of a task

const (
	// TaskStatePending is the state for a task when it's waiting to be processed or currently being processed
	TaskStatePending State = iota + 1
	// TaskStateAcked is the state for a task if it has been successfully completed
	TaskStateAcked
	// TaskStateNacked is the state for a task if it can not be processed
	TaskStateNacked
)

type Task

type Task interface {
	// Execute process this task
	Execute() error
	// HandleErr handle the error returned by Execute
	HandleErr(err error) error
	// RetryErr check whether to retry after HandleErr(Execute())
	RetryErr(err error) bool
	// Ack marks the task as successful completed
	Ack()
	// Nack marks the task as unsuccessful completed
	Nack()
	// State returns the current task state
	State() State
}

Task is the interface for tasks

type WeightedRoundRobinTaskSchedulerOptions added in v0.12.0

type WeightedRoundRobinTaskSchedulerOptions struct {
	Weights         dynamicconfig.MapPropertyFn
	QueueSize       int
	WorkerCount     dynamicconfig.IntPropertyFn
	DispatcherCount int
	RetryPolicy     backoff.RetryPolicy
}

WeightedRoundRobinTaskSchedulerOptions configs WRR task scheduler

func (*WeightedRoundRobinTaskSchedulerOptions) String added in v1.2.7

Jump to

Keyboard shortcuts

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