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

Job specs from external configuration #13

Open
mkozjak opened this issue Jul 30, 2017 · 1 comment
Open

Job specs from external configuration #13

mkozjak opened this issue Jul 30, 2017 · 1 comment

Comments

@mkozjak
Copy link

mkozjak commented Jul 30, 2017

Hi,

What if you want to store your task configuration parameters in a database or a yml/ini/js file?
How would you map to those functions?

@tohidplus
Copy link

I had this problem and this is how I solved it:

func main(){
   scheduleMethods := scheduleMethods()
   job:=func(){
     fmt.Println("Hello world")    
   }   
 // Call the methods and pass the parameters dynamically
  scheduleMethods["seconds"](10,job)
}
func scheduleMethods() map[string]func(every uint, function func()) {
	return map[string]func(every uint, function func()){
		"day": func(every uint, function func()) {
			_, _ = scheduler.Every(int(every)).Day().Run(function)
		},
		"hours": func(every uint, function func()) {
			_, _ = scheduler.Every(int(every)).Hours().Run(function)
		},
		"minutes": func(every uint, function func()) {
			_, _ = scheduler.Every(int(every)).Minutes().Run(function)
		},
		"seconds": func(every uint, function func()) {
			_, _ = scheduler.Every(int(every)).Seconds().Run(function)
		},
	}
}

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

No branches or pull requests

2 participants