Skip to content

Can gocron work with gin #50

Open
Open
@huyntsgs

Description

@huyntsgs

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions