Created
April 6, 2012 21:48
-
-
Save pamelafox/2323273 to your computer and use it in GitHub Desktop.
Geocoding with named task queue parameters on App Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queue: | |
- name: geocoding | |
rate: 1/m | |
retry_parameters: | |
task_retry_limit: 60 | |
task_age_limit: 3d | |
min_backoff_seconds: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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