Closed zoujunrong closed 3 years ago
It also happens on me. All of the jobs configured in format of cron expression does not work. cron version: v3.0.1 go version: 1.15.2
Me too...
The example was wrong. You should take 5 fields for AddFunc
funtion.
correct:
c.AddFunc("30 3 * * *", func() { fmt.Println("working") })
wrong:
c.AddFunc("0 30 * * * *", func() { fmt.Println("working") })
I read the code again, and found that the cron.New
function without parameter creates a "standardParser", which does not support the "Second" field
var standardParser = NewParser(
Minute | Hour | Dom | Month | Dow | Descriptor,
)
...
func New(opts ...Option) *Cron {
c := &Cron{
entries: nil,
chain: NewChain(),
add: make(chan *Entry),
stop: make(chan struct{}),
snapshot: make(chan chan []Entry),
remove: make(chan EntryID),
running: false,
runningMu: sync.Mutex{},
logger: DefaultLogger,
location: time.Local,
parser: standardParser,
}
for _, opt := range opts {
opt(c)
}
return c
}
To support "Second" field, create the cron object like this:
cron.New(cron.WithSeconds())
BTW,the doc on go.pkg.dev
needs to be updated because it's misleading now...
The example was wrong. You should take 5 fields for
AddFunc
funtion. correct:c.AddFunc("30 3 * * *", func() { fmt.Println("working") })
wrong:c.AddFunc("0 30 * * * *", func() { fmt.Println("working") })
c.AddFunc(" ", func() { fmt.Println("working") })
also not working.
Has this issue been solve? having issues just running c.AddFunc("* * * * *", func() { fmt.Println("working") })
Has this issue been solve? having issues just running
c.AddFunc("* * * * *", func() { fmt.Println("working") })
I was not able to get this line to work successfully, the only way I've found to get this to work is to use the above suggestion cron.New(cron.WithSeconds())
with the 6 field notation and it began working perfectly.
Hopefully this helps anyone landing on the page. I'm on v3.0.1.
这是来自QQ邮箱的假期自动回复邮件。 我已收到您的邮件,尽快给您回复,谢谢!
// "github.com/robfig/cron/v3"
use the latest version v3.0.1 and 3.0.0 is also not working, my useage was wrong?