李伟乐 2 years ago
parent 8d3562c5ee
commit b1986e6bfc
  1. 14
      xserver/cron.go

@ -5,23 +5,23 @@ import (
"github.com/robfig/cron"
)
type cronServer struct {
type Cron struct {
cr *cron.Cron
err error
}
func NewCron() *cronServer {
func NewCron() *Cron {
cr := cron.New()
return &cronServer{
return &Cron{
cr: cr,
}
}
func (c *cronServer) Register(spec string, fun func()) error {
func (c *Cron) Register(spec string, fun func()) error {
return c.cr.AddFunc(spec, fun)
}
func (c *cronServer) Start() error {
func (c *Cron) Start() error {
if c.err != nil {
return c.err
}
@ -29,11 +29,11 @@ func (c *cronServer) Start() error {
return nil
}
func (c *cronServer) Shutdown(ctx context.Context) error {
func (c *Cron) Shutdown(ctx context.Context) error {
c.cr.Stop()
return nil
}
func (c *cronServer) Name() string {
func (c *Cron) Name() string {
return "cron"
}

Loading…
Cancel
Save