为什么会在零点的时候还会执行一次计划呢?

bsdx866 · 2023-06-18 07:45:55 · 3376 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2023-06-18 07:45:55 的主题,其中的信息可能已经有所发展或是发生改变。

计划是要在每天的17点执行,为什么还会在零点的时候还会执行一次计划呢?

cat main.go
package main

import (
    "log"

    "github.com/robfig/cron/v3"
)

//计划任务
func Crontab(spec string, f func()) (cron.EntryID, error) {
    var c = cron.New(cron.WithSeconds())
    id, err := c.AddFunc(spec, f)
    c.Start()
    return id, err
}
func sayHello() {
    log.Println("hello world!")
}
func main() {
    // 秒0-59 分钟0-59 小时0-23 天或月1-31天 月1-12 星期0-6
    var spec string = "0 0 */17 * * ?"
    Crontab(spec, sayHello)
    select {}
}
tail nohup.out 
2023/06/17 17:00:00 hello world!
2023/06/18 00:00:00 hello world!

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

3376 次点击  
加入收藏 微博
10 回复  |  直到 2023-07-17 07:19:22
jiansoft
jiansoft · #1 · 2年之前

https://github.com/jiansoft/robin 試用看看另一個人性化語義的排程調度庫

zhang-jianqiang
zhang-jianqiang · #2 · 2年之前

你写的规则有问题呀,想17点执行:0 0 17 * * *

jan-bar
jan-bar · #3 · 2年之前

老铁没毛病吧

image.png

RafaelShin
RafaelShin · #4 · 2年之前
jan-barjan-bar #3 回复

老铁没毛病吧 ![image.png](https://static.golangjob.cn/230619/aa75fd8443b24df7eb4021b251b2826c.png)

你这是什么工具啊

bsdx866
bsdx866 · #5 · 2年之前
jan-barjan-bar #3 回复

老铁没毛病吧 ![image.png](https://static.golangjob.cn/230619/aa75fd8443b24df7eb4021b251b2826c.png)

你这个是什么工具给介绍一下呗?

jan-bar
jan-bar · #6 · 2年之前
RafaelShin
RafaelShin · #7 · 2年之前
jiansoftjiansoft #1 回复

https://github.com/jiansoft/robin 試用看看另一個人性化語義的排程調度庫

建议把discussion打开,可以在这里提问

bsdx866
bsdx866 · #8 · 2年之前
jiansoftjiansoft #1 回复

https://github.com/jiansoft/robin 試用看看另一個人性化語義的排程調度庫

谢谢,测试后没有问题,现在已经切换到robin做计划任务了。

gouwugaoshou5
gouwugaoshou5 · #9 · 2年之前

改为"* * 17 * * ?"

Neightly
Neightly · #10 · 2年之前
gouwugaoshou5gouwugaoshou5 #9 回复

改为"\* \* 17 \* \* ?"

典型的不看上下文,已经解释清楚了再来个错误比原始版本更严重的。

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传