You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey team! I am trying to leverage the job .RunNow() command but even with the simplest implementation I seem to get the error "gocron: Job: RunNow: scheduler unreachable", please see example code below and please let me know if I might be doing something wrong?
package main
import (
"fmt""time""github.com/go-co-op/gocron/v2"
)
funcmain() {
fmt.Println("Hello, 世界")
sch, err:=gocron.NewScheduler()
iferr!=nil {
fmt.Println("Failed to create new scheduler")
fmt.Print(err)
return
}
_, err=sch.NewJob(
gocron.DurationJob(
30*time.Second,
),
gocron.NewTask(
func(astring, bint) {
fmt.Println(a, b)
},
"hello",
1,
),
)
iferr!=nil {
fmt.Println("Failed to add job")
fmt.Print(err)
return
}
fmt.Println("Successfully added job")
sch.Start()
jobs:=sch.Jobs()
j0:=jobs[0]
err=j0.RunNow()
iferr!=nil {
fmt.Println("Failed to run job")
fmt.Print(err)
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey team! I am trying to leverage the job .RunNow() command but even with the simplest implementation I seem to get the error "gocron: Job: RunNow: scheduler unreachable", please see example code below and please let me know if I might be doing something wrong?
Playground:
https://go.dev/play/p/6MMUrYTeZDX
Please advise! Thank you!
Beta Was this translation helpful? Give feedback.
All reactions