Skip to content

Is there any way to monitor all jobs #513

Answered by JohnRoesler
iakirago asked this question in Q&A
Discussion options

You must be logged in to vote

Adding listeners to all the jobs is trivial, for example:

package main

import (
	"fmt"
	"time"

	"github.com/go-co-op/gocron"
)

func myBeforeJobRunsFunc() {
	fmt.Println("myBeforeJobRunsFunc")
}
func myAfterJobRunsFunc() {
	fmt.Println("myAfterJobRunsFunc")
}

func main() {
	s := gocron.NewScheduler(time.UTC)

	s.Every("1s").Do(func() {})
	s.Every("1s").Do(func() {})
	s.Every("1s").Do(func() {})
	s.Every("1s").Do(func() {})
	s.Every("1s").Do(func() {})

	for _, job := range s.Jobs() {
		job.SetEventListeners(myBeforeJobRunsFunc, myAfterJobRunsFunc)
	}
	s.StartBlocking()
}

I would like to know if there is a development plan for the global monitoring function, and if there is a correspon…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@iakirago
Comment options

@JohnRoesler
Comment options

@iakirago
Comment options

@JohnRoesler
Comment options

Answer selected by iakirago
@iakirago
Comment options

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