Golang version of Crontab

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Linux cron allows the system to perform a specified task at a specified time, and crontab is used to manage the cron mechanism. On the server side, cron can be used to perform certain tasks periodically, such as regular database backups, periodically compressing server-side data, and so on.

Now with the Golang server is growing, the server needs to periodically backup or compress or delete data is the norm. This week to learn the Golang version of the crontab, feel that the function is very convenient.

1 Package Main2 3 Import (4     "FMT"5     "Github.com/robfig/cron"6 )7 8 Func Main () {9Spec: ="0, 2 , *, *, *" //every morning .Tenc: =Cron. New () One C.addfunc (Spec, callyourfunc) A C.start () -     Select {} - } the  - func Callyourfunc () { -Fmt. Println ("Callyourfunc come here.") - } +  - //Callyourfunc function is called every 2:30

Although this program is short, it has been implemented periodically to perform specific tasks. For the specified time, it is generally recorded in the configuration file, and then through the Golang parsing configuration file to implement the code part without modification, and only need to modify the configuration file can easily change the specified time.

Reference Document: http://ju.outofmemory.cn/entry/65356

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.