Documentation ¶
Overview ¶
Package cron is a generated GoMock package.
Index ¶
Constants ¶
const ( ExpressEveryMin = "* * * * *" ExpressEvery5Min = "*/5 * * * *" ExpressEvery10Min = "*/10 * * * *" ExpressEvery30Min = "*/30 * * * *" ExpressEveryHour = "0 * * * *" // 每小时整点执行 ExpressEveryDay = "0 1 * * *" // 凌晨1:00执行 ExpressEveryMonth = "0 1 1 * *" // 每个月 )
cron格式`*/1 * * * *`,分(0-59) 时(0-23) 日(1-31) 月(1-12) 天(0-6)
Variables ¶
var DefaultScheduleCfg = &SchedulerCfg{ TimeZone: "Asia/Shanghai", Async: true, SingletonModeAll: true, }
DefaultScheduleCfg 默认Schedule配置
Functions ¶
This section is empty.
Types ¶
type DistributeLocker ¶
type DistributeLocker interface { Lock(key string, ttl time.Duration) error UnLock(key string) error }
DistributeLocker 分布式锁接口 该接口主要是针对多个JOB执行时刻,进行并发控制,确保在不同机器上的Job仅执行一次行
type MockLocker ¶
type MockLocker struct {
// contains filtered or unexported fields
}
MockLocker is a mock of DistributeLocker interface
func NewMockLocker ¶
func NewMockLocker(ctrl *gomock.Controller) *MockLocker
NewMockLocker creates a new mock instance
func (*MockLocker) EXPECT ¶
func (m *MockLocker) EXPECT() *MockLockerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockLockerMockRecorder ¶
type MockLockerMockRecorder struct {
// contains filtered or unexported fields
}
MockLockerMockRecorder is the mock recorder for MockLocker
func (*MockLockerMockRecorder) Lock ¶
func (mr *MockLockerMockRecorder) Lock(key, ttl interface{}) *gomock.Call
Lock indicates an expected call of Lock
func (*MockLockerMockRecorder) UnLock ¶
func (mr *MockLockerMockRecorder) UnLock(key interface{}) *gomock.Call
UnLock indicates an expected call of UnLock
type RedisLocker ¶
type RedisLocker struct {
// contains filtered or unexported fields
}
RedisLocker 基于Redis实现的分布式锁,
func NewRedisLocker ¶
func NewRedisLocker(redisURL string) (*RedisLocker, error)
NewRedisLocker 创建一个Redis分布式锁 Examples:
redis://user:password@localhost:6789/3?dial_timeout=3&db=1&read_timeout=6s&max_retries=2
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler Cron调度程序
func NewScheduler ¶
func NewScheduler(cfg *SchedulerCfg) (*Scheduler, error)
NewScheduler 初始化一个cron 调度器
type SchedulerCfg ¶
type SchedulerCfg struct { TimeZone string // 时区配置,默认为Asia/Shanghai Async bool // 启动job的方式是阻塞还是非阻塞 SingletonModeAll bool // 启动job是否采用单例模式,单例模式下若job如果之前有运行且未完成,则调度器不会重复调度同类型新的job任务(若无特殊要求,推荐开启) }
SchedulerCfg Cron调度器配置
type Task ¶
type Task struct { Name string // job描述名称 Express string // cron格式`*/1 * * * *`,分(0-59) 时(0-23) 日(1-31) 月(1-12) 周天(0-6) Exec func() // job调度后执行的内容 Locker DistributeLocker // 分布式Redis锁 TTL time.Duration // 分布式锁,过期时间 }
Task 待执行的JOB任务
func (*Task) SetDistributeLocker ¶
func (t *Task) SetDistributeLocker(locker DistributeLocker, ttl time.Duration) *Task
SetDistributeLocker 设置task任务依赖的分布式锁,以及持锁时间 更细粒度的cron任务持有的分布式锁,可以基于task自定义,否则采用默认调度器的统一持锁时间