commons

package module
v0.0.0-...-3dc6625 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 4 Imported by: 3

README

COMMONS

This is a mod for everyone who want to customize theirself dcron drivers.

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 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 etcd/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)

	WithOption(opt Option) (err error)
}

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.

type LoggerOption

type LoggerOption struct{ Logger dlog.Logger }

func NewLoggerOption

func NewLoggerOption(logger dlog.Logger) LoggerOption

func (LoggerOption) Type

func (to LoggerOption) Type() int

type Option

type Option interface {
	Type() int
}

type TimeoutOption

type TimeoutOption struct{ Timeout time.Duration }

func NewTimeoutOption

func NewTimeoutOption(timeout time.Duration) TimeoutOption

func (TimeoutOption) Type

func (to TimeoutOption) Type() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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