Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created April 6, 2012 21:48
Show Gist options
  • Save pamelafox/2323273 to your computer and use it in GitHub Desktop.
Save pamelafox/2323273 to your computer and use it in GitHub Desktop.
Geocoding with named task queue parameters on App Engine
queue:
- name: geocoding
rate: 1/m
retry_parameters:
task_retry_limit: 60
task_age_limit: 3d
min_backoff_seconds: 120
def new_user_from_form(form):
user = models.User())
update_user_from_form(user, form)
deferred.defer(models.User.calculate_timezone_for_user, user.get_id(), _queue="geocoding")
return user
class User(db.Model):
# stuff
@classmethod
def calculate_timezone_for_user(cls, user_or_id):
user = convert_to_user(user_or_id)
user.calculate_timezone()
def calculate_timezone(self):
import geocoder
try:
geocoder_client = geocoder.Geocoder()
geocoder_result = geocoder_client.geocode(self.location.encode('utf-8'))
self.latlng = db.GeoPt(*geocoder_result.coordinates)
except geocoder.GeocoderError, err:
if err.status == geocoder.GeocoderError.G_GEO_OVER_QUERY_LIMIT:
logging.info('Went over geocoding query limit.')
raise
else:
logging.error('Error geocoding location for user %s: %s' % (self.get_id(), err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment