Skip to content

Many task and one call at a time #109

Discussion options

You must be logged in to vote

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)
	})
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by JohnRoesler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants