Documentation ¶
Index ¶
- Constants
- type Keeper
- func (k *Keeper) AliveNodes() ([]string, error)
- func (k *Keeper) Close()
- func (k *Keeper) Init() error
- func (k *Keeper) IsAlive(workerKey string) (bool, error)
- func (k *Keeper) IsLeader() bool
- func (k *Keeper) NewMutex(key string) mod.DistributedMutex
- func (k *Keeper) WorkerKey() string
- func (k *Keeper) WorkerNumber() int
- type KeeperOption
- type LeaderPayload
- type LockDetail
- type MongoMutex
- type Payload
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 mongo implement
func (*Keeper) AliveNodes ¶
AliveNodes get all alive nodes
func (*Keeper) NewMutex ¶
func (k *Keeper) NewMutex(key string) mod.DistributedMutex
NewMutex(key string) create a new distributed mutex
func (*Keeper) WorkerNumber ¶
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 // mongo connection string ConnStr string Database 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 LeaderPayload ¶
type LeaderPayload struct { ID string `bson:"_id"` WorkerKey string `bson:"workerKey"` UpdatedAt time.Time `bson:"updatedAt"` }
LeaderPayload leader election dto
type LockDetail ¶
type MongoMutex ¶
type MongoMutex struct {
// contains filtered or unexported fields
}
func (*MongoMutex) Lock ¶
func (m *MongoMutex) Lock(ctx context.Context, ops ...mod.LockOptionOp) error
Click to show internal directories.
Click to hide internal directories.