I am new to golang. I am trying to write a gocron job which runs every 2 minutes. A separate function is creating new instance of this cron job based on some event. So there will be multiple cron jobs running, executing same function but different arguments .
The issue is whenever new instance is of this cron job is created, the arguments values are being overwritten and all cron jobs are running with the latest argument passed from
func StatusRoutine( ) {
//based on some event
arg := "someNewvalue"
go StartCron(arg)
}
func StartCron(arg string) {
gocron.Every(2).Minutes().Do(someFunction, arg)
<-gocron.Start()
}
func someFunction (arg string){
//do something
}
How to make each instance cron job run based on the original arguments?
New value for “arg” is actually being passed to StatusRoutine( ) at runtime based on some event.
you can think it as
func StatusRoutine(arg string ) {
go StartCron(arg)
}
The calling function of StatusRoutine is passing new “arg” values every time, e.g. A new user is accessing the application and the “arg” is the email id of user.