dsw7547 2018-01-29 06:30
浏览 54

如何在App Engine中使用time.sleep()一段时间?

I want call to two GET requests from my App in App Engine. I want to sleep for few minutes after calling the first request and then call the second request. If I add time.sleep() in the code I am able to deploy code but if I hit the URL of the App it gives me ->
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

health-policy.go

isHealthy, err = h.CampaignService.Run(ctx)
return err
if isHealthy {
        startTime = time.Now().Format(time.RFC3339)
        //The line below causes 500 error
        time.Sleep(3 * time.Minute)
        isHealthy, err = h.ReportService.GenerateReport(ctx, startTime)
    }

campaign-run-service.go

req, err = http.NewRequest("GET", "URL1", nil)
client := urlfetch.Client(ctx)
res, err = client.Do(req)
if err == nil && res.StatusCode == http.StatusOK {
    return true, err
}
fmt.Println("Error in Run Service ->", err)
return false, err

generate-report-service.go

req, err = http.NewRequest("GET", "URL2", nil)
client := urlfetch.Client(ctx)
res, err = client.Do(req)
if err == nil && res.StatusCode == http.StatusOK && res.ContentLength > 400 {
    return true, err
}
return false, err

I am new to App Engine, also using sleep in app engine code a good idea if not than what is the alternative?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记