scheduler

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearSchedulers

func ClearSchedulers()

ClearSchedulers is only used in test

func RegisterSchedulerConstructor

func RegisterSchedulerConstructor(taskType string, constructor Constructor, opts ...RegisterOption)

RegisterSchedulerConstructor registers the constructor of Scheduler.

func RegisterSubtaskExectorConstructor

func RegisterSubtaskExectorConstructor(taskType string, constructor SubtaskExecutorConstructor, opts ...SubtaskExecutorRegisterOption)

RegisterSubtaskExectorConstructor registers the constructor of SubtaskExecutor.

Types

type Constructor

type Constructor func(taskMeta []byte, step int64) (Scheduler, error)

Constructor is the constructor of Scheduler.

type InternalScheduler

type InternalScheduler interface {
	Start()
	Stop()
	Run(context.Context, *proto.Task) error
	Rollback(context.Context, *proto.Task) error
}

InternalScheduler defines the interface of an internal scheduler.

func NewInternalScheduler

func NewInternalScheduler(ctx context.Context, id string, taskID int64, taskTable TaskTable, pool Pool) InternalScheduler

NewInternalScheduler creates a new InternalScheduler.

type InternalSchedulerImpl

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

InternalSchedulerImpl is the implementation of InternalScheduler.

func (*InternalSchedulerImpl) Rollback

func (s *InternalSchedulerImpl) Rollback(ctx context.Context, task *proto.Task) error

Rollback rollbacks the scheduler task.

func (*InternalSchedulerImpl) Run

func (s *InternalSchedulerImpl) Run(ctx context.Context, task *proto.Task) error

Run runs the scheduler task.

func (*InternalSchedulerImpl) Start

func (*InternalSchedulerImpl) Start()

Start starts the scheduler.

func (*InternalSchedulerImpl) Stop

func (s *InternalSchedulerImpl) Stop()

Stop stops the scheduler.

type Manager

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

Manager monitors the global task table and manages the schedulers.

func (*Manager) Start

func (m *Manager) Start()

Start starts the Manager.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the Manager.

type ManagerBuilder

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

ManagerBuilder is used to build a Manager.

func NewManagerBuilder

func NewManagerBuilder() *ManagerBuilder

NewManagerBuilder creates a new ManagerBuilder.

func (*ManagerBuilder) BuildManager

func (b *ManagerBuilder) BuildManager(ctx context.Context, id string, taskTable TaskTable) (*Manager, error)

BuildManager builds a Manager.

type MockInternalScheduler

type MockInternalScheduler struct {
	mock.Mock
}

MockInternalScheduler is a mock of InternalScheduler.

func (*MockInternalScheduler) Rollback

func (m *MockInternalScheduler) Rollback(ctx context.Context, task *proto.Task) error

Rollback implements InternalScheduler.Rollback.

func (*MockInternalScheduler) Run

func (m *MockInternalScheduler) Run(ctx context.Context, task *proto.Task) error

Run implements InternalScheduler.Run.

func (*MockInternalScheduler) Start

func (m *MockInternalScheduler) Start()

Start implements InternalScheduler.Start.

func (*MockInternalScheduler) Stop

func (m *MockInternalScheduler) Stop()

Stop implements InternalScheduler.Stop.

type MockMinimalTask

type MockMinimalTask struct{}

MockMinimalTask is a mock of MinimalTask.

func (MockMinimalTask) IsMinimalTask

func (MockMinimalTask) IsMinimalTask()

IsMinimalTask implements MinimalTask.IsMinimalTask.

type MockPool

type MockPool struct {
	mock.Mock
}

MockPool is a mock of Pool.

func (*MockPool) ReleaseAndWait

func (m *MockPool) ReleaseAndWait()

ReleaseAndWait implements Pool.ReleaseAndWait.

func (*MockPool) Run

func (m *MockPool) Run(f func()) error

Run implements Pool.Run.

func (*MockPool) RunWithConcurrency

func (m *MockPool) RunWithConcurrency(funcs chan func(), _ uint32) error

RunWithConcurrency implements Pool.RunWithConcurrency.

type MockScheduler

type MockScheduler struct {
	mock.Mock
}

MockScheduler is a mock of Scheduler.

func (*MockScheduler) CleanupSubtaskExecEnv

func (m *MockScheduler) CleanupSubtaskExecEnv(ctx context.Context) error

CleanupSubtaskExecEnv implements Scheduler.CleanupSubtaskExecEnv.

func (*MockScheduler) InitSubtaskExecEnv

func (m *MockScheduler) InitSubtaskExecEnv(ctx context.Context) error

InitSubtaskExecEnv implements Scheduler.InitSubtaskExecEnv.

func (*MockScheduler) OnSubtaskFinished

func (m *MockScheduler) OnSubtaskFinished(ctx context.Context, subtask []byte) error

OnSubtaskFinished implements Scheduler.OnSubtaskFinished.

func (*MockScheduler) Rollback

func (m *MockScheduler) Rollback(ctx context.Context) error

Rollback implements Scheduler.Rollback.

func (*MockScheduler) SplitSubtask

func (m *MockScheduler) SplitSubtask(ctx context.Context, subtask []byte) ([]proto.MinimalTask, error)

SplitSubtask implements Scheduler.SplitSubtask.

type MockSubtaskExecutor

type MockSubtaskExecutor struct {
	mock.Mock
}

MockSubtaskExecutor is a mock of SubtaskExecutor.

func (*MockSubtaskExecutor) Run

Run implements SubtaskExecutor.Run.

type MockTaskTable

type MockTaskTable struct {
	mock.Mock
}

MockTaskTable is a mock of TaskTable. TODO(gmhdbjd): move this to storage package.

func (*MockTaskTable) GetGlobalTaskByID

func (t *MockTaskTable) GetGlobalTaskByID(id int64) (*proto.Task, error)

GetGlobalTaskByID implements TaskTable.GetTaskByID.

func (*MockTaskTable) GetGlobalTasksInStates

func (t *MockTaskTable) GetGlobalTasksInStates(states ...interface{}) ([]*proto.Task, error)

GetGlobalTasksInStates implements TaskTable.GetTasksInStates.

func (*MockTaskTable) GetSubtaskInStates

func (t *MockTaskTable) GetSubtaskInStates(instanceID string, taskID int64, states ...interface{}) (*proto.Subtask, error)

GetSubtaskInStates implements SubtaskTable.GetSubtaskInStates.

func (*MockTaskTable) HasSubtasksInStates

func (t *MockTaskTable) HasSubtasksInStates(instanceID string, taskID int64, states ...interface{}) (bool, error)

HasSubtasksInStates implements SubtaskTable.HasSubtasksInStates.

func (*MockTaskTable) UpdateSubtaskStateAndError

func (t *MockTaskTable) UpdateSubtaskStateAndError(id int64, state string, _ string) error

UpdateSubtaskStateAndError implements SubtaskTable.UpdateSubtaskState.

type Pool

type Pool interface {
	Run(func()) error
	RunWithConcurrency(chan func(), uint32) error
	ReleaseAndWait()
}

Pool defines the interface of a pool.

func NewMockPool

func NewMockPool(int) Pool

NewMockPool creates a new mock pool.

type RegisterOption

type RegisterOption func(opts *schedulerRegisterOptions)

RegisterOption is the register option of Scheduler.

type Scheduler

type Scheduler interface {
	// InitSubtaskExecEnv is used to initialize the environment for the subtask executor.
	InitSubtaskExecEnv(context.Context) error
	// SplitSubtask is used to split the subtask into multiple minimal tasks.
	SplitSubtask(ctx context.Context, subtask []byte) ([]proto.MinimalTask, error)
	// CleanupSubtaskExecEnv is used to clean up the environment for the subtask executor.
	CleanupSubtaskExecEnv(context.Context) error
	// OnSubtaskFinished is used to handle the subtask when it is finished.
	OnSubtaskFinished(ctx context.Context, subtask []byte) error
	// Rollback is used to rollback all subtasks.
	Rollback(context.Context) error
}

Scheduler defines the interface of a scheduler. User should implement this interface to define their own scheduler.

type SubtaskExecutor

type SubtaskExecutor interface {
	Run(ctx context.Context) error
}

SubtaskExecutor defines the interface of a subtask executor. User should implement this interface to define their own subtask executor.

type SubtaskExecutorConstructor

type SubtaskExecutorConstructor func(minimalTask proto.MinimalTask, step int64) (SubtaskExecutor, error)

SubtaskExecutorConstructor is the constructor of SubtaskExecutor.

type SubtaskExecutorRegisterOption

type SubtaskExecutorRegisterOption func(opts *subtaskExecutorRegisterOptions)

SubtaskExecutorRegisterOption is the register option of SubtaskExecutor.

type TaskTable

type TaskTable interface {
	GetGlobalTasksInStates(states ...interface{}) (task []*proto.Task, err error)
	GetGlobalTaskByID(taskID int64) (task *proto.Task, err error)
	GetSubtaskInStates(instanceID string, taskID int64, states ...interface{}) (*proto.Subtask, error)
	UpdateSubtaskStateAndError(id int64, state string, err string) error
	HasSubtasksInStates(instanceID string, taskID int64, states ...interface{}) (bool, error)
}

TaskTable defines the interface to access task table.

Jump to

Keyboard shortcuts

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