Giter Site home page Giter Site logo

crontab's Introduction

golang的定时任务

用法(usage)

引入

import "github.com/goodluckxu-go/crontab"

调用方法

func main() {
    go crontab.NewCron("* * * 29 * 2").
        SetFun(func(ctx *crontab.Context) {
        // 定时任务执行地方
        }).
        SetBeforeTime(time.Now()). // 设置上次执行时间,可不设置
        Run()
    crontab.Wait() // 等待终止命令
}

crontab.NewCron方法注解

1. * * * * * * 表示 秒 分 时 日 月 周
2. 秒(0-59),分(0-59),时(0-23),日(1-31),月(1-12),周(0-6)0表示星期天
3. *支持的符号为 ',','/','-' 三种
4. ','表示分割多个,如:1,2,3 * * * * * 表示 1,2,3秒执行
5. '-'表示执行区间,如:1-5 * * * * * 表示1-5秒直接的秒都执行包含1和5
6. '/'表示每执行,如:*/2 * * * * * 表示每2秒执行一次
7. 特殊如:4/2 * * * * * 表示从第4秒开始每2秒执行
8. 特殊如:4-50/2 * * * * * 表示在4-50秒区间每2秒执行一次
9. 特殊如:1,2,3,4-5,*/10 * * * * * 表示1,2,3秒执行一次,4-5区间都执行一次,每10秒执行一次。
10. 多个规则直接重复的数只计数1次

crontab.Context注解

ctx.Stop() // 表示停止该定时任务

crontab's People

Contributors

xuruipro avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.