Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] For all jobs, add a global event listening function #515

Closed
iakirago opened this issue Jun 14, 2023 · 1 comment
Closed

[FEATURE] For all jobs, add a global event listening function #515

iakirago opened this issue Jun 14, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@iakirago
Copy link

iakirago commented Jun 14, 2023

For all jobs, add a global event listening function.

When any one or more of the following events occur in any job, the set callback function will be triggered.

'EVENT_SCHEDULER_STARTED', 'EVENT_SCHEDULER_SHUTDOWN', 'EVENT_SCHEDULER_PAUSED', 'EVENT_SCHEDULER_RESUMED', 'EVENT_ALL_JOBS_REMOVED','EVENT_JOB_ADDED', 'EVENT_JOB_REMOVED', 'EVENT_JOB_MODIFIED', 'EVENT_JOB_EXECUTED', 'EVENT_JOB_ERROR', 'EVENT_JOB_MISSED'

Hope to have the following implementation,

package main

import (
	"fmt"
	"time"
       "github.com/go-co-op/gocron"
)

func myListenerFunc() {
	fmt.Println("myListenerFunc")
}

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

	s.SetEventListener(myListenerFunc, EVENT_JOB_EXECUTED|EVENT_JOB_ERROR)
	s.StartBlocking()
}

The above is my suggestion, and the idea also has shortcomings, such as how myListenerFunc distinguishes different events and performs different logic functions. Please correct any deficiencies. Due to limited personal ability, I can only propose this idea, thank you!

@JohnRoesler
Copy link
Contributor

At least some initial events exist and can be set globally now.

Feel free to open additional feature requests as you use it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants