Skip to content

wangbaolong/go-cron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
    

About

A cron library for go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages