【发布时间】:2018-10-05 02:02:58
【问题描述】:
我正在做一个 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字段或方法)
谁能告诉我这个。
谢谢:)
【问题讨论】: