I'm creating a scheduler using Golang's crontab and resty.v2 to call a POST api(Dropbox file upload api).
When I'm invoking the file upload method manually its working fine. But when the same method is invoked via the crontab scheduler its not making the rest call.
Interesting fact is that, it's neither throwing any error nor providing any rest call response.
PFB the scheduler code to invoke the upload method:
func StartJob() {
ctab := crontab.New()
for _, v := range strings.Split(os.Getenv("schedules"), commaSeparator) {
match, _ := regexp.MatchString(regex, v)
if match == true {
hhmm := strings.Split(v, colonSeparator)
expresion := fmt.Sprintf(cronExpression, hhmm[1], hhmm[0])
ctab.MustAddJob(expresion, func() {
go service.Upload(dropboxEndpoint, dropboxAccessToken, os.Getenv("hkpath"))
})
} else {
fmt.Printf("Not acceptable time-format : %s\n", v)
}
}}
And here is the upload method code:
func Upload(dropboxEndpoint string, dropboxAccessToken string, path string) {
_, fileName := filepath.Split(path)
fileBytes, fileErr := ioutil.ReadFile(path)
if fileErr == nil {
fmt.Println(path)
resp, restErr := client.R().
SetBody(fileBytes).
SetContentLength(true).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", dropboxAccessToken)).
SetHeader("Dropbox-API-Arg", fmt.Sprintf("{\"path\": \"/home/f1/%s/%s\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}", os.Getenv("name"), fileName)).
SetHeader("Content-Type", "application/octet-stream").
Post(dropboxEndpoint)
if restErr != nil {
log.Fatal(restErr)
} else {
fmt.Println(resp)
}
} else {
log.Fatal(fileErr)
}}
Any idea what's the wrong I'm doing?