Many task and one call at a time #109
-
I have two request in different times, but when have 1 minute two jobs are called and the server has reached its maximum number of sessions. I don't wanna upgrade the session in my request server, i want manage the call one call at a time, without conflict. s := gocron.NewScheduler(time.UTC)
_, _ = s.Every(30).Seconds().Do(getX)
_, _ = s.Every(60).Seconds().Do(getY)
s.StartBlocking() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @darlandieterich - sounds like you'd like to be able to supply a custom |
Beta Was this translation helpful? Give feedback.
-
This can be accomplished with https://pkg.go.dev/github.com/go-co-op/gocron#Scheduler.SetMaxConcurrentJobs Use reschedule mode https://pkg.go.dev/github.com/go-co-op/gocron#pkg-constants For example: package main
import (
"fmt"
"time"
"github.com/go-co-op/gocron"
)
func main() {
s := gocron.NewScheduler(time.UTC)
s.SetMaxConcurrentJobs(1, gocron.RescheduleMode)
_, _ = s.Every(1).Seconds().Do(func() {
fmt.Println("This will run once every 5 seconds even though it is scheduled every second because maximum concurrent job limit is set.")
time.Sleep(5 * time.Second)
})
} |
Beta Was this translation helpful? Give feedback.
This can be accomplished with https://pkg.go.dev/github.com/go-co-op/gocron#Scheduler.SetMaxConcurrentJobs
Use reschedule mode https://pkg.go.dev/github.com/go-co-op/gocron#pkg-constants
For example: