daemon

package
v0.0.0-...-0f65a33 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Campaign

func Campaign(c *clientv3.Client, parentCtx context.Context, wg *sync.WaitGroup, CampaignPrefix string) (success <-chan struct{})

这里返回的 channel 表示已经成功选主为 leader 所有worker可以监听这个channel,这种实现可以让worker阻塞等待节点成为leader,而不是轮询是否是leader节点。

func InitDaemon

func InitDaemon(wg *sync.WaitGroup) (cancel context.CancelFunc)

Types

type Option

type Option func(info *WorkerInfo)

func WithBusySleepTime

func WithBusySleepTime(BusySleepTime time.Duration) Option

func WithCtx

func WithCtx(ctx context.Context) Option

func WithIdleSleepTime

func WithIdleSleepTime(IdleSleepTime time.Duration) Option

func WithMaxPanicRecoverCount

func WithMaxPanicRecoverCount(MaxPanicRecoverCount int) Option

func WithName

func WithName(name string) Option

应用自定义配置

func WithWg

func WithWg(wg *sync.WaitGroup) Option

type TaskFunc

type TaskFunc func() (idle bool, err error)

type WorkerInfo

type WorkerInfo struct {
	Name                 string
	IdleSleepTime        time.Duration
	BusySleepTime        time.Duration
	MaxPanicRecoverCount int
	Task                 TaskFunc
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(task TaskFunc, opts ...Option) (w *WorkerInfo)

func (*WorkerInfo) Work

func (w *WorkerInfo) Work()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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