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 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名