Files
timerx/types.go
T

45 lines
1.3 KiB
Go
Raw Normal View History

2023-11-27 22:37:33 +08:00
package timerx
2023-08-27 23:39:58 +08:00
2023-11-11 17:26:46 +08:00
import (
"context"
"time"
)
2023-08-27 23:39:58 +08:00
type timerStr struct {
Callback callback // 需要回调的方法
CanRunning chan (struct{}) // 是否允许执行
BeginTime time.Time // 初始化任务的时间
NextTime time.Time // [删]下一次执行的时间
SpaceTime time.Duration // 任务间隔时间
2024-04-04 10:58:57 +08:00
TaskId string // 任务ID 全局唯一键
2023-11-13 23:49:42 +08:00
ExtendData interface{} // 附加参数
2024-04-04 10:58:57 +08:00
JobType JobType // 任务类型
JobData *JobData // 任务时间数据
2023-08-27 23:39:58 +08:00
}
2024-04-04 10:58:57 +08:00
type JobType string
2023-11-27 22:37:33 +08:00
2024-04-04 10:58:57 +08:00
const (
JobTypeEveryDay JobType = "every_day"
JobTypeEveryHour JobType = "every_hour"
JobTypeEveryMinute JobType = "every_minute"
JobTypeEverySecond JobType = "every_second"
JobTypeEveryMonth JobType = "every_month"
// 根据间隔时间执行
JobTypeInterval JobType = "interval"
)
2023-11-11 17:26:46 +08:00
2024-04-04 10:58:57 +08:00
type JobData struct {
Month *time.Month // 每年的第几个月
Weekday *time.Weekday // 每周的周几
Day *int // 每月的第几天
Hour *int // 每天的第几个小时
Minute *int // 每小时的第几分钟
Second *int // 每分钟的第几秒
}
var nextTime = time.Now() // 下一次执行的时间
2023-11-11 17:26:46 +08:00
// 定义各个回调函数
2023-11-13 23:49:42 +08:00
type callback func(ctx context.Context, extendData interface{}) error