doulipi3742 2019-06-28 10:15
浏览 48

无法通过cron选项卡进行resty.v2 POST调用

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
", 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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划