[BUG] - Task not being called #266
-
Describe the bugI've written a simple program but can't for the life of me figure out why it isn't executing the task function. To ReproduceFirst I create a new scheduler: s := gocron.NewScheduler(time.UTC) Then I specify how often the task should occur (every 10 seconds): s.Every(10).Do(task) Finally, I start the task with: s.StartAsync() But the task function (previously defined to print "Task is being performed" never executes. A playground link can be found here. VersionI am using version Expected behaviorI expected the program to call the task function. Additional contextI've tried adding a |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi @okridgway Running the playground link you provided I see it's going to always evaluate true as the scheduler Try this: package main
import (
"fmt"
"log"
"time"
"github.com/go-co-op/gocron"
)
var task = func() {
fmt.Println("Task is being performed.")
}
func main() {
fmt.Println("Task is starting.")
s := gocron.NewScheduler(time.UTC)
_, err := s.Every(10).Do(task)
if err != nil {
log.Fatal(s)
}
s.StartBlocking()
} It timed out for me in the playground, but runs locally just fine. |
Beta Was this translation helpful? Give feedback.
-
Ok, I've got it working now (thank you!) but don't quite understand why |
Beta Was this translation helpful? Give feedback.
-
Can you paste the code you're running where you're seeing that have to set it to a variable? The README is correct. For example, this works for me: package main
import (
"fmt"
"time"
"github.com/go-co-op/gocron"
)
var task = func() {
fmt.Println("Task is being performed.")
}
func main() {
fmt.Println("Task is starting.")
s := gocron.NewScheduler(time.UTC)
s.Every(10).Do(task)
s.StartBlocking()
} |
Beta Was this translation helpful? Give feedback.
-
@okridgway I transferred your issue here as I deem it a discussion vs. a bug with gocron - I'm happy to continue helping here! |
Beta Was this translation helpful? Give feedback.
-
The job doesn't execute the task, i have tried it without the AT() and it works fine, i.e _, err := newScheduler.Every(1).Second().Do(cron.Task("jobDetails.UserSlackId", "jobDetails.WorkspaceSlackId", uuid.New()))
job := scheduler.Name(jobDetails.Id.String()).Every(jobDetails.Intervals).Weeks() |
Beta Was this translation helpful? Give feedback.
Can you paste the code you're running where you're seeing that have to set it to a variable? The README is correct.
For example, this works for me: