Documentation
¶
Overview ¶
Package cronrunner provides module wrapper for github.com/robfig/cron/v3.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNilCronAfterInit = fmt.Errorf("cron.Cron was nil, WithCron is required option") ErrAddFuncToNilCron = fmt.Errorf("WithCron has to be applied before WithFunc") )
Functions ¶
This section is empty.
Types ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is a wrapper around cron.Cron implementing service.Module interface.
func New ¶
New creates Runner with given options. Options are applied in same order as they were provided. WithCron is required option.
Example ¶
runner := cronrunner.New( cronrunner.WithCron(cron.New(cron.WithSeconds())), cronrunner.WithFunc("@every 1s", func() { fmt.Println("cron job executed") syscall.Kill(syscall.Getpid(), syscall.SIGINT) //nolint: errcheck }), ) err := service.Run(service.Modules{siglistener.New(os.Interrupt), runner}) if err != nil { fmt.Println(err) os.Exit(1) }
Output: cron job executed
Example (CustomAddFunc) ¶
var ( id cron.EntryID err error ) c := cron.New(cron.WithSeconds()) id, err = c.AddFunc("@every 1s", func() { fmt.Printf("hello from job with id: %d\n", id) syscall.Kill(syscall.Getpid(), syscall.SIGINT) //nolint: errcheck }) if err != nil { fmt.Println(err) os.Exit(1) } err = service.Run(service.Modules{ siglistener.New(os.Interrupt), cronrunner.New(cronrunner.WithCron(c)), }) if err != nil { fmt.Println(err) os.Exit(1) }
Output: hello from job with id: 1
Click to show internal directories.
Click to hide internal directories.