Search code examples
google-app-enginepyramid

Google App engine needs periodic restarting


I have a module that works fine when I push it to app engine. When it works it logs stuff nicely and the logs are accessible in the console logs viewer. But then after a while it just stops working and when I try to access any url give me 500 server errors with no info (it just says waiting 30 seconds might be a good idea). When this happens nothing gets logged for requests.

If I restart the module (by pushing my code to app engine) then it works for a little while again.

The module is running a Pyramid app and the configuration file looks a little something like:

application: my_app
module: my_module
version: dev
runtime: python27
api_version: 1
threadsafe: false

instance_class: B2
basic_scaling:
  max_instances: 2
  idle_timeout: 10m

handlers:
- url: /actions/.*
  script: my_module.application
  login: admin
- url: /.*
  script: my_module.application

builtins:
- appstats: off

libraries:
- name: webob
  version: latest
- name: setuptools
  version: latest

includes:
- mapreduce/include.yaml

I think what is happening is that it's hitting the idle timeout and shutting down. I need requests to the module to turn it back on again. How do I do that?

Let me know if you need more info, I'm an app engine noob at this stage. Any help would be greatly appreciated.


Solution

  • When a module start, App Engine call the url /_ah/start. You mustn't handle this request. In you my_module.application you need to add in the handler who match this request :

        def get(self):
            # Let module start
            if "X-Appengine-Cron" in self.request.headers or "X-AppEngine-TaskName" in self.request.headers  or "X-Appengine-Failfast" in self.request.headers:
                return