first commit
This commit is contained in:
40
pkg/crontab/crontab.go
Normal file
40
pkg/crontab/crontab.go
Normal file
@ -0,0 +1,40 @@
|
||||
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()
|
||||
}
|
Reference in New Issue
Block a user