0

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?

Gurjit Singh
  • 31
  • 1
  • 4
  • Are you in the standard or flexible environment? And how is this triggered, is it when you perform a request on the server? Be aware that the [standard environment](https://cloud.google.com/appengine/docs/the-appengine-environments) has a 60s timeout on requests. – Marc Jan 29 '18 at 13:12
  • @Marc Thanks for the reply, I am in the standard environment yes it is triggered when you perform request on the server, I have read about flexible environment do you think flexible environment is more suitable for such kind of use case – Gurjit Singh Jan 29 '18 at 15:45
  • 1
    The docs clearly state your requests will timeout after 1 minute, so if you want a 3 minute sleep within your request (which is just odd), you need to use the flexible environment. – Marc Jan 29 '18 at 15:47
  • Thanks @Marc I know 3 minutes sleep is odd but it is required – Gurjit Singh Jan 29 '18 at 16:39

0 Answers0