0

On Google App Engine, there are multiple ways a request can start: a web request, a cron job, a taskqueue, and probably others as well.

How could you (especially on Managed VM) determine the time when your current request began?

One solution is to instrument all of your entry points, and save the start time somewhere, but it would be nice if there was an environment variable or something that told when the request started. The reason this is important is because many GAE requests have deadlines (either 60 seconds or 10 minutes in various scenarios), and it's helpful to determine how much time you have left in a request when you are doing some additional work.

speedplane
  • 15,673
  • 16
  • 86
  • 138

2 Answers2

0

You can see all this information in the logs in your Developer console. You can also add more data to the logs in your code, as necessary.

See Writing Application Logs.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Apologies if my question was not clear, but I wanted to know how to do this programatically, i.e., if the request is currently running, try to figure out how much time you have left. – speedplane Mar 11 '16 at 16:01
  • Take a look at shutdown hooks: https://cloud.google.com/appengine/docs/java/modules/ – Andrei Volgin Mar 11 '16 at 18:00
0

We don't specifically expose anything that lets you know how much time is left on the current request. You should be able to do this by recording the time at the entrypoint of a request, and storing it in a thread local static.

The need for this sounds... questionable. Why are you doing this? It may be a better idea to use a worker / queue pattern with polling for something that could take a long time.

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
  • That is what I am doing now, and it's annoying as there are multiple entry points (cron jobs, deferred, normal requests, etc.), and you need to instrument each of these entry points. Django middleware helps, but there is no middleware for the deferred library. I do this largely to set a reasonable timeout on 3rd party url fetches. I want to make sure I always set the timeout to less than the time I have to complete the request, to ensure I have enough time to clean things up if it fails. – speedplane Mar 16 '16 at 18:30