我已经开发了一个应用程序,并为各种功能(例如完成一项工作,负责一项工作等)创建了路由(作为REST api)。然后使用cron设置了路由,并使用以下代码每10分钟运行一次。
package cron
import (
"gopkg.in/robfig/cron.v2"
"api/config"
)
func main(){
cron.RunCron()
NewRouter()
}
func RunCron() {
c := cron.New()
c.AddFunc("@every 0h10m0s", RunAutoCharge)
c.Start()
}
func RunAutoCharge(){
utils.ExecuteCommand("sh " +config.GetBasePath() + "sh/auto_charge_bookings.sh")
}
函数中提到的sh文件包含如下REST API网址,它们在cron运行时运行
#!/bin/bash
curl "127.0.0.1:8080/merchantname/auto-charge-bookings"
此设置正常运行,但向客户收取了两次费用,经分析,我发现api在五分钟内运行了两次,这本不应该
请帮助我解决问题