Skip to content
/ cron Public

Based on github.com/robfig/cron/v3, but more convenient

Notifications You must be signed in to change notification settings

kainhuck/cron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cron

Based on github.com/robfig/cron/v3, but more convenient

Usage

package main

import (
    "fmt"
    "time"
    "github.com/kainhuck/cron"
)

func main() {
	crond := cron.NewCron()
	crond.Start(nil)

	hello1 := crond.AddSecondJob(1, hello(1), cron.WithRunMode(cron.ModeJobSerial))
	hello2 := crond.AddSecondJob(1, hello(2), cron.WithRunMode(cron.ModeTimeFirst))

	time.Sleep(10 * time.Second)
	crond.Call(hello1)
	crond.RemoveJob(hello2)
	time.Sleep(10 * time.Second)
	crond.RemoveJob(hello1)
}

func hello(id int) func() {
	return func() {
		fmt.Println("hello", id)
		time.Sleep(2 * time.Second)
	}
}

About

Based on github.com/robfig/cron/v3, but more convenient

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages