mongo

package
v0.0.0-...-70df4e6 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const LeaderKey = "leader"

Variables

This section is empty.

Functions

This section is empty.

Types

type Keeper

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

Keeper mysql implement

func NewKeeper

func NewKeeper(opt *KeeperOption) *Keeper

NewKeeper

func (*Keeper) AliveNodes

func (k *Keeper) AliveNodes() ([]string, error)

AliveNodes get all alive nodes

func (*Keeper) Close

func (k *Keeper) Close()

close component

func (*Keeper) Init

func (k *Keeper) Init() error

Init

func (*Keeper) IsAlive

func (k *Keeper) IsAlive(workerKey string) (bool, error)

IsAlive check if a worker still alive

func (*Keeper) IsLeader

func (k *Keeper) IsLeader() bool

IsLeader indicate the component if is leader node

func (*Keeper) NewMutex

func (k *Keeper) NewMutex(key string) mod.DistributedMutex

NewMutex(key string) create a new distributed mutex

func (*Keeper) WorkerKey

func (k *Keeper) WorkerKey() string

WorkerKey must match `xxxx-1` format

func (*Keeper) WorkerNumber

func (k *Keeper) WorkerNumber() int

WorkerNumber get the the key number of Worker key, if here is a WorkKey like `worker-1`, then it will return "1"

type KeeperOption

type KeeperOption struct {
	// Key the work key, must be the format like "xxxx-{{number}}", number is the code of worker
	Key string
	// mysql connection string
	ConnStr string
	// the prefix will append to the database
	Prefix string
	// UnhealthyTime default 5s, campaign and heartbeat time will be half of it
	UnhealthyTime time.Duration
	// Timeout default 2s
	Timeout time.Duration
}

KeeperOption

type Worker

type Worker struct {
	WorkerKey   string    `gorm:"column:worker_key;unique;comment:WorkerKey"`
	WorkerType  string    `gorm:"column:worker_type;comment:WorkerType"`
	UpdatedAt   time.Time `gorm:"column:updated_at;comment:UpdatedAt"`
	HeartbeatAt time.Time `gorm:"column:heartbeat_at;comment:HeartBeatAt"`
}

func (Worker) TableName

func (Worker) TableName() string

Jump to

Keyboard shortcuts

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