Corn and Seconds results are inconsistent #183
Answered
by
JohnRoesler
Chen840302
asked this question in
Q&A
-
I have a job1 that is executed every three seconds and takes 5 seconds to execute. func (job *Job)task() {
job.Status = "Running"
log.Println( "RUN", job.Name)
time.Sleep(time.Second*5)
job.Status = "Done"
log.Println(job.Status)
}
func main() {
log.Println("Starting...")
tagMap := make(map[string]*Job)
job1 := Job{Name: "job1", Tag: "job1", Cron: "*/3 * * * * *",Status: "Done"}
tagMap["job1"] = &job1
s := gocron.NewScheduler(time.UTC)
s.WaitForScheduleAll()
s.StartAsync()
for{
time.Sleep(time.Second)
for k, v := range tagMap{
switch v.Status {
case "Running":
s.RemoveByTag(k)
case "Waiting":
//fmt.Println(v.Status, v.Name)
case "Done":
s.CronWithSeconds(v.Cron).Tag(v.Tag).Do(job1.task)
//s.Every(3).Seconds().Tag(v.Tag).Do(job1.task)
v.Status = "Waiting"
}
}
}
} I use the seconds function is right, |
Beta Was this translation helpful? Give feedback.
Answered by
JohnRoesler
May 31, 2021
Replies: 1 comment 1 reply
-
Looks like we aren’t handling the wait for scheduled logic in cron! Thanks for reporting |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JohnRoesler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like we aren’t handling the wait for scheduled logic in cron! Thanks for reporting