go language based on timed tasks cron module

Recently result of the need to write a fixed timing task, but requires written go. Search of the investigation documents, summarize

First install cron about this module, this in my opinion is similar to crontab, Baidu interested can learn more about linux crontab

go get github.com/robfig/cron

Code section is:

        c := cron.New()
	spec := "0 0 * * * "
	c.AddFunc(spec, check_dt)
	c.Start()

  This part is placed inside the main function. is a function of the timing check_dt you perform, if a relatively small direct func () {} on a properly.

  Explain spec, which is a string calibration execution time, in a spirit of respect the author's specific asynchronously to the back after reading a few words https://www.jianshu.com/p/e629d637bf4c (this article presented in more detail, but some pit did not say). windows under spec This string is in: a few seconds time-day Monday, so the information contained six things. But under linux only be accurate to the minute, also less one.

  Then on top of that blog which say that you can use? * In place, I do not really recommend this, or directly * like, mainly because of a metaphysical had a problem, solve the subsequent update will come back.

  The last such execution once per min * / 1 * * * * In this way, and so, of the details or refer to the above article.

Guess you like

Origin www.cnblogs.com/XiaoBoya/p/12015983.html