dongruo0909 2016-01-02 10:53
浏览 1134

cron golang每隔24小时运行一次吗?

cron golang is running after every 24 hours but when I am trying to change the system time, it is not invoking.

code:

package main;

import(
    "fmt"
    "strconv"
    "strings"
    "gopkg.in/robfig/cron.v2"
    "time"
    )

func Envoke_ASSET_INFO() {    
    fmt.Println("Invoking Envoke_ASSET_INFO ", time.Now())
}

func main(){
    C:=cron.New()

    min:=strconv.Itoa(int(17))
    h:=strconv.Itoa(int(16))

    sep:="0"+" "+min+" "+h+" "+"*"+" "+"*"+" "+"*"
    fmt.Println("SPECIFATION PASSED TO FUNCTION :", sep)    
    C.AddFunc(sep, Envoke_ASSET_INFO )
    C.Start()
    select{}
}

When I am running this program it is evoking my function. But when I change my system time (+24 hours) to check the next evoking it is not happening.

  • 写回答

1条回答 默认 最新

  • dongpan1308 2016-01-02 16:07
    关注

    This is not how cron works. Cron won't run overdue tasks when you change system time. Think what would happen if it worked that way and you turned your machine on after 2 days with job scheduled to run every 5 minutes. If you really want to test it that way you should change the system time to a time just before your job is supposed to run and wait to see if it does.

    Personally I think that it's a better idea to pass hour and minute as parameters and check if the job is running on next minute or something.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?