41 lines
628 B
Go
41 lines
628 B
Go
|
package crontab
|
||
|
|
||
|
import (
|
||
|
"github.com/robfig/cron/v3"
|
||
|
)
|
||
|
|
||
|
var _ Crontab = (*crontab)(nil)
|
||
|
|
||
|
type Crontab interface {
|
||
|
i()
|
||
|
AddFunc(spec string, cmd func()) (entryID cron.EntryID, err error)
|
||
|
Entries() []cron.Entry
|
||
|
Stop()
|
||
|
}
|
||
|
|
||
|
type crontab struct {
|
||
|
cron *cron.Cron
|
||
|
}
|
||
|
|
||
|
func New() Crontab {
|
||
|
return &crontab{
|
||
|
cron: cron.New(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (c *crontab) i() {}
|
||
|
|
||
|
func (c *crontab) AddFunc(spec string, cmd func()) (entryID cron.EntryID, err error) {
|
||
|
entryID, err = c.cron.AddFunc(spec, cmd)
|
||
|
c.cron.Start()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c *crontab) Stop() {
|
||
|
c.cron.Stop()
|
||
|
}
|
||
|
|
||
|
func (c *crontab) Entries() []cron.Entry {
|
||
|
return c.cron.Entries()
|
||
|
}
|