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
547 B

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