cron

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeName is the instrumentation scope name.
	ScopeName = "github.com/rushteam/beauty/pkg/service/cron/trace.go"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

type Cron struct {
	*cron.Cron
	// contains filtered or unexported fields
}

func New

func New(opts ...CronOptions) *Cron

func (*Cron) Start

func (s *Cron) Start(ctx context.Context) error

func (*Cron) String

func (s *Cron) String() string

type CronHandlerOptions

type CronHandlerOptions func(cfg *cronHandlerCfg)

func HandlerName

func HandlerName(name string) CronHandlerOptions

type CronOptions

type CronOptions func(c *Cron)

func WithCronHandler

func WithCronHandler(spec string, handler func(ctx context.Context) error, opts ...CronHandlerOptions) CronOptions

func WithLeaderElector

func WithLeaderElector(elector dlock.Elector, key string) CronOptions

WithLeaderElector 让整个 Cron 只在选主(leader election)当选期间跑任务, 解决"多实例部署下每个实例都各跑一遍定时任务"的重复执行问题。

key 是参选的选举标识(同一组要互斥的多个实例须用同一个 key,通常按服务名 定,如 "myservice-cron")。elector 通常传 pkg/infra/etcd 的 DLock(生产, 跨实例)或 pkg/dlock.NewMemory()(单实例/测试)。

语义:未当选时不注册/不运行任何任务(Start 阻塞在选举上);当选后启动全部 任务,失去 leader 身份(网络分区/进程崩溃/主动放弃)时立即停止全部任务并 重新参选。不配置此项时行为不变(直接 Start,不经过选举)。

func WithMeterProvider

func WithMeterProvider(m metric.MeterProvider) CronOptions

func WithRecover

func WithRecover(recoverHandler func(r any)) CronOptions

func WithTraceProvider

func WithTraceProvider(t trace.TracerProvider) CronOptions

Jump to

Keyboard shortcuts

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