leaderworker

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

type IGeneral

type IGeneral interface {
	// ListWorkers list all worker
	ListWorkers(ctx context.Context) ([]types.WorkerID, error)
	// WatchPrefix watch events occurred by etcd key with specified prefix, and do the passed handler function.
	WatchPrefix(ctx context.Context, prefix string, putHandler, deleteHandler func(context.Context, *clientv3.Event))
	// UpdateLogicTask update the logic task, it can stop a running task, continue a stopped task or update a task context.
	UpdateLogicTask(ctx context.Context, logicTask types.LogicTask, operation *types.UpdateOperation) error
}

type ILeader

type ILeader interface {
	// RunLeader run leader instances
	RunLeader(ctx context.Context) error
	// OnLeader register listener which webhook function will be called before and after leader execute.
	OnLeader(l types.Listener)
	// InitWorkersList init the list which contains all worker information.
	InitWorkersList(ctx context.Context) error
	// OnWorkerAdd register webhook function which will be called when the instance run as leader and
	// add worker to its worker list
	OnWorkerAdd(webhookFunc types.WebhookFunc)
	// OnWorkerRemove register webhook function which will be called when instance run as leader and
	// remove worker from its worker list
	OnWorkerRemove(webhookFunc types.WebhookFunc)
	// AssignLogicTaskToWorker assign task to worker
	AssignLogicTaskToWorker(ctx context.Context, workerID types.WorkerID, task types.LogicTask) error
}

ILeader the leader is responsible for worker add or remove and assign task.

type IWorker

type IWorker interface {
	// RunWorker run a worker instance
	RunWorker(ctx context.Context) error
	// HandleTask handle the task which assigned by worker
	HandleTask(ctx context.Context, task types.LogicTask) error
}

IWorker the worker is responsible for task handler.

type Interface

type Interface interface {
	ILeader
	IWorker
	IGeneral
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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