worker

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = fmt.Errorf("not found")
	ErrNilWorker         = fmt.Errorf("nil worker")
	ErrNoWorkerID        = fmt.Errorf("no worker id")
	ErrNoWorkerType      = fmt.Errorf("no worker type")
	ErrInvalidWorkerType = fmt.Errorf("invalid worker type")
	ErrNoCreatedTime     = fmt.Errorf("no created time")
	ErrMarshal           = fmt.Errorf("cannot marshal")
)

Functions

This section is empty.

Types

type HeartbeatDetector

type HeartbeatDetector interface {
	DetectHeartbeat(ctx context.Context) (alive bool)
}

type ID

type ID string

func NewID

func NewID() ID

func NewLogicTaskID

func NewLogicTaskID() ID

func (ID) String

func (id ID) String() string

type LogicTask

type LogicTask interface {
	GetLogicID() LogicTaskID
	GetData() []byte
}

LogicTask is the logic task for worker to process.

func NewLogicTask

func NewLogicTask(logicID LogicTaskID, data []byte) LogicTask

type LogicTaskID

type LogicTaskID string

func (LogicTaskID) String

func (id LogicTaskID) String() string

type OpFunc

type OpFunc func(*defaultWorker)

func WithHandler

func WithHandler(h handler) OpFunc

func WithHeartbeatDetector

func WithHeartbeatDetector(h func(ctx context.Context) bool) OpFunc

func WithID

func WithID(id ID) OpFunc

func WithType

func WithType(typ Type) OpFunc

type Type

type Type string
var (
	Official  Type = "official"
	Candidate Type = "candidate"

	AllTypes = []Type{Official, Candidate}
)

func (Type) String

func (t Type) String() string

func (Type) Valid

func (t Type) Valid() bool

type Worker

type Worker interface {
	consistent.Member
	json.Marshaler
	json.Unmarshaler
	HeartbeatDetector

	GetID() ID
	GetType() Type
	SetType(typ Type)
	GetCreatedAt() time.Time
	Handle(ctx context.Context, task LogicTask)
}

Worker .

func New

func New(ops ...OpFunc) Worker

func NewFromBytes

func NewFromBytes(bytes []byte) (Worker, error)

Jump to

Keyboard shortcuts

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