Я делаю работу cron для непрерывного мониторинга данных.В функции задания cron есть условие, при котором я хочу остановить задание cron, но я не знаю, как отключить задание cron.Ниже приводится функция, которую я использую: -
CronController.go
func AutomaticChargedCron(c *gin.Context) {
err:= //there is function which gives the value to err
if err != nil {
fmt.Println("There is something wrong please try again later.", err)
//I want to stop the cron here
}
}
cron.go
package cron
import (
"gopkg.in/robfig/cron.v2"
)
func RunCron() {
c := cron.New()
c.AddFunc("@every 0h10m0s", AutomaticChargedCron)
c.Start()
}
func AutomaticChargedCron() {
utils.ExecuteCommand("sh " + config.GetBasePath() + "sh/charged.sh")
}
charged.sh
curl "http://localhost:8080/api/v1/charged"
Router.go
func main() {
router := gin.Default()
router.GET("/charged", controllers.AutomaticChargedCron)
router.Run()
router.Run(":8080")
}
Я использовал c.Stop()
, но выдает ошибку
c.Stop undefined (тип * gin.Context не имеет поля или метод Stop)
Может кто-нибудь сказать мне об этом.
Спасибо:)