Skip to content

Instantly share code, notes, and snippets.

@erlichmen
Created June 4, 2014 06:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erlichmen/d81501cafb59bf2a9b97 to your computer and use it in GitHub Desktop.
Save erlichmen/d81501cafb59bf2a9b97 to your computer and use it in GitHub Desktop.
Better deferred handler names for debugging and appstats
- url: /_ah/queue/deferred/.*
script: google.appengine.ext.deferred.application
from google.appengine.ext import deferred
def do_defer(obj, *args, **kwargs):
_DEFAULT_URL = "/_ah/queue/deferred"
tag = kwargs.pop("_tag") if kwargs.get('_tag') else None
if not tag and kwargs.get('_queue'):
tag = kwargs.get('_queue')
kwargs['_url'] = '%s/%s' % (_DEFAULT_URL, tag or 'notag')
deferred.defer(obj, *args, **kwargs)
@erlichmen
Copy link
Author

When using deferred in App Engine you have the problem that all diagnostic is on the same handler although you might be using it for different functionality.

This means in the the event log, appstat and requests diagnostics (on the main dashboard page) you will see everything under the /_ah/queue/deferred entry.

In order to get better context to which each defer belongs use do_defer instead of deferred.defer and add the above yaml code to your app.yaml.

The code will add the queue name to the handler path (e.g. /_ah/queue/deferred/my-queue) or you can pass the _tag property (do_defer(my_method, _tag='method-tag')) to control the path text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment