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

Can gocron work with gin #50

Open
huyntsgs opened this issue Feb 9, 2018 · 7 comments
Open

Can gocron work with gin #50

huyntsgs opened this issue Feb 9, 2018 · 7 comments

Comments

@huyntsgs
Copy link

huyntsgs commented Feb 9, 2018

I want to use gocron with gin router. But it seems that gin router and gocron block each other.
If i start goncron before router.Run, the genData will be done, but can not get response from /ex/getdata. If i start router.Run before gocron.Start(), I can get response from /ex/getdata but genData job is not executed.

func main() {
	data := &Data{}
	router := gin.Default()
	router.GET("/ex/getdata", getData)
	
	gocron.Every(1).Second().Do(genData)
	<-gocron.Start()
	router.Run(":8888")
}
@icobani
Copy link

icobani commented Feb 23, 2018

I have same problem.

@huyntsgs
Copy link
Author

huyntsgs commented Mar 16, 2018

I backed with github.com/robfig/cron and all work fine

@laczar
Copy link

laczar commented Jan 18, 2019

This one gives a nice answer im using right now. https://stackoverflow.com/questions/52719015/using-gin-gonic-and-some-scheduler-in-golang

@ariefannur
Copy link

i have same problem

@ariefannur
Copy link

I backed with github.com/robfig/cron and all work fine

could you mind to give sample implementation about it?

@huyntsgs
Copy link
Author

huyntsgs commented May 8, 2019

@ariefannur
Copy link

how about every (time) get data from db and send broadcast notif with gcm. @huyntsgs

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

No branches or pull requests

5 participants