golang  crontab ,  规则同 Java spring crontab WheelTimer golang crontab , 规则同 Java spring crontab

farmerx2018-03-19 18:07:59 • 1162 次点击    
这是一个分享于 2018-03-19 18:07:59 的项目,其中的信息可能已经有所发展或是发生改变。

wheeltimer

Linux
*    *    *    *    *    *
-    -    -    -    -    -
|    |    |    |    |    |
|    |    |    |    |    + year [optional]
|    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
|    |    |    +---------- month (1 - 12)
|    |    +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)

Java(Spring) AND GO(wheeltimer)
*    *    *    *    *    *    *
-    -    -    -    -    -    -
|    |    |    |    |    |    |
|    |    |    |    |    |    + year [optional]
|    |    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
|    |    |    |    +---------- month (1 - 12)
|    |    |    +--------------- day of month (1 - 31)
|    |    +-------------------- hour (0 - 23)
|    +------------------------- min (0 - 59)
+------------------------------ second (0 - 59)

crontab规则表达式验证网址

很实用的工具,推广一下: crontab表达式验证网址

wheeltimer: Use github.com/farmerx/wheeltimer

wg := &sync.WaitGroup{}

wheel := NewTimingWheel(context.TODO())
timeout := NewOnTimeOut(func() {
    fmt.Println(`hahahah `)
})
timerID := wheel.AddTimer(`1 7/13 * * * *`, timeout)
fmt.Printf("Add timer %d\n", timerID)
c := time.After(9 * time.Minute)
wg.Add(1)
go func() {
    for {
        select {
        case timeout := <-wheel.TimeOutChannel():
            timeout.Callback()
        case <-c:
            wg.Done()
        }
    }
}()
wg.Wait()
wheel.Stop()

crontab, golang crontab, wheeltimerRead More

Latest commit to the master branch on 8-8-2018
Download as zip
授权协议:
MIT
开发语言:
go 查看源码»
操作系统:
windows, mac OS, linux
1162 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传