Documentation ¶
Overview ¶
/ Author:koangel / jackliu100@gmail.com / 负责分析并解析字符串格式并转换成一个time
/ Author:koangel / jackliu100@gmail.com / 每个单独的执行模块,结构中越简单越好
/ Author:koangel / jackliu100@gmail.com / 负责分析并解析字符串格式并转换成一个time
/ Author:koangel / jackliu100@gmail.com / 调度器负责单独的timer处理以及调度器行为
Index ¶
- Constants
- Variables
- func AtTime(timeFmt string, startAt time.Time, loc *time.Location) (*time.Time, error)
- func Format(Id int64, layout string) string
- func InitGrapeScheduler(t time.Duration, ars bool)
- func List() map[int64]string
- func NewFromJson(json string, fn GrapeExecFn, args ...interface{}) int64
- func NewTickerLoop(tick, count int, startAt time.Time, endAt time.Time, fn GrapeExecFn, ...) int64
- func NewTickerOnce(tick int, startAt time.Time, endAt time.Time, fn GrapeExecFn, ...) int64
- func NewTimeDataLoop(data string, count int, startAt time.Time, endAt time.Time, fn GrapeExecFn, ...) int64
- func NewTimeDataOnce(data string, startAt time.Time, endAt time.Time, fn GrapeExecFn, ...) int64
- func PanicTrace(kb int) []byte
- func Parser(dateFmt string) (*time.Time, error)
- func ParserLoc(dateFmt string, startAt time.Time, loc *time.Location) (*time.Time, error)
- func ParserStartAt(startAt time.Time, dateFmt string) (*time.Time, error)
- func PeekNextId() int64
- func SaveAll() []string
- func SetCreateGUID(fn func() int64)
- func SetGuidSeed(seed int64) error
- func StopTimer(Id int64)
- func String(Id int64) string
- func ToJson(Id int64) string
- type GrapeExecFn
- type GrapeScheduler
- type GrapeTimer
Constants ¶
View Source
const ( TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" // Day 00:00:00 每天的几点几分执行 DayRegexp = `Day\s[0-9]{2}:[0-9]{2}:[0-9]{2}` // Week 1 00:00:00 每周几的几点执行 WeekRegexp = `Week\s[0-9]{1,2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}` // Month 1 00:00:00 每月几日的几点几分执行 // 但是如果本月不存在该日期则不执行并报错 MonthRegexp = `Month\s[0-9]{1,2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}` )
View Source
const ( Day = "Day" Week = "Week" Month = "Month" )
View Source
const ( LoopOnce = 1 UnlimitLoop = -1 )
Variables ¶
View Source
var CDebugMode bool = true
开启日志调试模式 默认开启 错误类信息不受该控制
View Source
var DayCRegexp, _ = regexp.Compile(DayRegexp)
View Source
var LocationFormat = "Asia/Shanghai"
默认的通用时区字符串,通过修改他会更改分析后的日期结果 默认为上海时区
View Source
var MonthCRegexp, _ = regexp.Compile(MonthRegexp)
View Source
var RecoverPanic = func(err error) { fmt.Println(err.Error()) }
对于默认Panic Recover函数处理
View Source
var SkipWaitTask bool = true
如果上次任务未执行完成,默认方式还是跳过 默认跳过,单协程模式下,不处理
View Source
var UseAsyncExec bool = true
创建GO去执行到期的任务 默认开启
View Source
var WeekCRegexp, _ = regexp.Compile(WeekRegexp)
Functions ¶
func InitGrapeScheduler ¶
初始化全局整个调度器 调度器的粒度不建议小于1秒,会导致Cpu爆炸 不建议低于1秒钟,如果低于100毫秒 则自动设置为100毫秒有效防止CPU爆炸 ars = auto set runtime,自动设置Cpu数量
func NewFromJson ¶
func NewFromJson(json string, fn GrapeExecFn, args ...interface{}) int64
通过json构造timer
func NewTickerLoop ¶
func NewTickerLoop(tick, count int, startAt time.Time, endAt time.Time, fn GrapeExecFn, args ...interface{}) int64
循环可控版本
func NewTickerOnce ¶
func NewTickerOnce(tick int, startAt time.Time, endAt time.Time, fn GrapeExecFn, args ...interface{}) int64
以下函数均为自动ID 间隔为毫秒 运行一个tick并返回一个Id
func NewTimeDataLoop ¶
func NewTimeDataOnce ¶
func NewTimeDataOnce(data string, startAt time.Time, endAt time.Time, fn GrapeExecFn, args ...interface{}) int64
格式分析时钟
func PanicTrace ¶
func Parser ¶
/ 基本格式 Day or Week or Month or Year / like : Type DayNum Time / format: Day 00:00:00 / 返回一个处理好的下一个时间
func ParserStartAt ¶ added in v0.0.3
func PeekNextId ¶
func PeekNextId() int64
func SetCreateGUID ¶
func SetCreateGUID(fn func() int64)
func SetGuidSeed ¶
Types ¶
type GrapeExecFn ¶
type GrapeExecFn interface{}
type GrapeScheduler ¶
type GrapeScheduler struct {
// contains filtered or unexported fields
}
var GScheduler *GrapeScheduler = nil
func (*GrapeScheduler) SaveAll ¶
func (c *GrapeScheduler) SaveAll() []string
func (*GrapeScheduler) String ¶
func (c *GrapeScheduler) String(id int64) string
func (*GrapeScheduler) ToJson ¶
func (c *GrapeScheduler) ToJson(id int64) string
type GrapeTimer ¶
type GrapeTimer struct { Id int64 `json:"id"` NextTime int64 `json:"next_time"` RunMode int `json:"run_mode"` TimeData string `json:"time_data"` LoopCount int32 `json:"loop_count"` // -1为无限执行 //控制任务执行区间,如果为空则忽略区间 StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` // contains filtered or unexported fields }
func (*GrapeTimer) Format ¶
func (c *GrapeTimer) Format(layout string) string
func (*GrapeTimer) ParserJson ¶
func (c *GrapeTimer) ParserJson(s string) *GrapeTimer
func (*GrapeTimer) Stop ¶
func (c *GrapeTimer) Stop()
func (*GrapeTimer) String ¶
func (c *GrapeTimer) String() string
Click to show internal directories.
Click to hide internal directories.