driver

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionTypeTimeout = 0x600
	OptionTypeLogger  = 0x601
)
View Source
const GlobalKeyPrefix = "distributed-cron:"

GlobalKeyPrefix is a global redis key prefix

Variables

This section is empty.

Functions

func GetKeyPre

func GetKeyPre(serviceName string) string

func GetNodeId

func GetNodeId(serviceName string) string

func GetStableJobStore

func GetStableJobStore(serviceName string) string

func GetStableJobStoreTxKey

func GetStableJobStoreTxKey(serviceName string) string

func TimePre

func TimePre(t time.Time, preDuration time.Duration) int64

Types

type DriverV2

type DriverV2 interface {
	// init driver
	Init(serviceName string, opts ...Option)
	// get nodeID
	NodeID() string
	// get nodes
	GetNodes(ctx context.Context) (nodes []string, err error)

	// register node to remote server (like redis),
	// will create a goroutine to keep the connection.
	// And then continue for other work.
	Start(ctx context.Context) (err error)

	// stop the goroutine of keep connection.
	Stop(ctx context.Context) (err error)
	// contains filtered or unexported methods
}

There is only one driver for one dcron. Tips for write a user-defined Driver by yourself.

  1. Confirm that `Stop` and `Start` can be called for more times.
  2. Must make `GetNodes` will return error when timeout.

func NewRedisDriver

func NewRedisDriver(redisClient *redis.Client) DriverV2

func NewRedisZSetDriver

func NewRedisZSetDriver(redisClient *redis.Client) DriverV2

type LoggerOption

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

func NewLoggerOption

func NewLoggerOption(logger dlog.Logger) LoggerOption

func (LoggerOption) Type

func (to LoggerOption) Type() int

type Option

type Option interface {
	Type() int
}

type RedisDriver

type RedisDriver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RedisDriver) GetNodes

func (rd *RedisDriver) GetNodes(ctx context.Context) (nodes []string, err error)

func (*RedisDriver) Init

func (rd *RedisDriver) Init(serviceName string, opts ...Option)

func (*RedisDriver) NodeID

func (rd *RedisDriver) NodeID() string

func (*RedisDriver) Start

func (rd *RedisDriver) Start(ctx context.Context) (err error)

func (*RedisDriver) Stop

func (rd *RedisDriver) Stop(ctx context.Context) (err error)

type RedisZSetDriver

type RedisZSetDriver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RedisZSetDriver) GetNodes

func (rd *RedisZSetDriver) GetNodes(ctx context.Context) (nodes []string, err error)

func (*RedisZSetDriver) Init

func (rd *RedisZSetDriver) Init(serviceName string, opts ...Option)

func (*RedisZSetDriver) NodeID

func (rd *RedisZSetDriver) NodeID() string

func (*RedisZSetDriver) Start

func (rd *RedisZSetDriver) Start(ctx context.Context) (err error)

func (*RedisZSetDriver) Stop

func (rd *RedisZSetDriver) Stop(ctx context.Context) (err error)

type TimeoutOption

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

func NewTimeoutOption

func NewTimeoutOption(timeout time.Duration) TimeoutOption

func (TimeoutOption) Type

func (to TimeoutOption) Type() int

Jump to

Keyboard shortcuts

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