I have a developed an application and created routes ( as REST api ) for different functionalities like complete a job, charge a job etc. There routes are then setup with cron to run every 10 minutes with following code.
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")
}
the sh file mentioned in the function contains rest api url as follows which runs when cron runs
#!/bin/bash
curl "127.0.0.1:8080/merchantname/auto-charge-bookings"
this setup works properly but charges the customers twice , on analysis I found that the api is running twice in five minutes which should not be
Please help me to resolve the issue