I'm using JobRunner (https://github.com/bamzi/jobrunner) for scheduler and GIn-gonic framework for my Golang project (I'm just learning Go for about 1 week).
I have tried the package and it works. Problem is when i would like to connect to my database, i cannot access gin context inside the schedule function
func ScheduleUrl() {
jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1)
jobrunner.Schedule("@every 20s", CheckExpiredUrl{})
}
// Job Specific Functions
type CheckExpiredUrl struct {
// filtered
}
// ReminderEmails.Run() will get triggered automatically.
func (e CheckExpiredUrl) Run() {
// Queries the DB
// Sends some email
fmt.Println("Every 20 sec Check Expired Url ")
db := c.MustGet("db").(*mgo.Database)
urls := []models.Url{}
err := db.C(models.CollectionUrl).Find(nil).Sort("-expired_at").All(&urls)
if err != nil {
c.Error(err)
}
}
I need to use c *gin.Context
inside jobrunner function, and how to do that?