You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
505 B

2 years ago
package xserver
import (
"context"
"github.com/robfig/cron"
)
2 years ago
type Cron struct {
2 years ago
cr *cron.Cron
err error
}
2 years ago
func NewCron() *Cron {
2 years ago
cr := cron.New()
2 years ago
return &Cron{
2 years ago
cr: cr,
}
}
2 years ago
func (c *Cron) Register(spec string, fun func()) error {
2 years ago
return c.cr.AddFunc(spec, fun)
}
2 years ago
func (c *Cron) Start() error {
2 years ago
if c.err != nil {
return c.err
}
c.cr.Start()
return nil
}
2 years ago
func (c *Cron) Shutdown(ctx context.Context) error {
2 years ago
c.cr.Stop()
return nil
}
2 years ago
func (c *Cron) Name() string {
2 years ago
return "cron"
}