Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Crontab ¶
Crontab struct representing cron table
Example ¶
package main import ( "fmt" "log" ) func main() { ctab := New() // create cron table // MustAddJob panics on wrong syntax or problem with func and args for easier initialization ctab.MustAddJob("0 12 * * *", myFunc3) ctab.MustAddJob("* * * * *", myFunc2, "on every minute", 123) // fn with args ctab.MustAddJob("*/2 * * * *", myFunc2, "every two min", 18) // or use AddJob if you want to test the error err := ctab.AddJob("* * * * *", myFunc) if err != nil { log.Println(err) return } // all your other app code as usual, or put sleep timer for example // time.Sleep(5 * time.Minute) } func myFunc() { fmt.Println("Helo, world") } func myFunc3() { fmt.Println("Noon!") } func myFunc2(s string, n int) { fmt.Printf("We have params here, string `%s` and nymber %d\n", s, n) } type MyTypeInterface struct { ID int Name string } func (m MyTypeInterface) Bar() string { return "OK" } type MyTypeNoInterface struct { ID int Name string } func myFuncStruct(m MyTypeInterface) { fmt.Println("Custom type as param") } func myFuncInterface(i Foo) { i.Bar() } type Foo interface { Bar() string }
Output:
func (*Crontab) AddJob ¶
AddJob to cron table
Returns error if:
* Cron syntax can't be parsed or out of bounds
* fn is not function
* Provided args don't match the number and/or the type of fn args
func (*Crontab) MustAddJob ¶
MustAddJob is like AddJob but panics if there is an problem with job
It simplifies initialization, since we usually add jobs at the beggining so you won't have to check for errors (it will panic when program starts). It is a similar aproach as go's std lib package `regexp` and `regexp.Compile()` `regexp.MustCompile()` MustAddJob will panic if:
* Cron syntax can't be parsed or out of bounds
* fn is not function
* Provided args don't match the number and/or the type of fn args