Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.04 KB

README.md

File metadata and controls

41 lines (29 loc) · 1.04 KB

cron lib for go

A support cron expression、 fixed-rate、fixed-delay cron lib

example

import "github.com/wangbaolong/go-cron/cron"
    

    var schedule = cron.NewSchedule()
    schedule.Schedule("Scheduled", 300, func() {
                logger.Info("A task exec")
    })

    schedule.ScheduleAtFixedRate("ScheduleAtFixedRate", 5, 5, func() {
        logger.Info("B task running spend time initDelay:5s period:5")
        time.Sleep(time.Second * 10)
    })

    schedule.ScheduleWithFixedDelay("ScheduleWithFixedDelay", 5, 5, func() {
        logger.Info("C task running spend time initDelay:5s period:5")
        time.Sleep(time.Second * 10)
    })

    _ = schedule.ScheduleWithSpec("specTask", "*/20 * * * * *", func() {
        logger.Info("D task running spend time 20s")
        time.Sleep(time.Minute * 2)
    })

    _ = schedule.ScheduleWithSpec("specTask", "@every 10s", func() {
        logger.Info("E task running spend time @every 10s")
        time.Sleep(time.Minute * 2)
    })

    // schedule.ShutdownNow()