Skip to content
This repository
Browse code

Cache better

  • Loading branch information...
commit 219203b1d41c5d155ab005be5e8e15b4f8fcbf61 1 parent b070701
Brian Klug dustball authored

Showing 3 changed files with 13 additions and 5 deletions. Show diff stats Hide diff stats

  1. +3 1 cron.yaml
  2. +7 1 main.py
  3. +3 3 utils.py
4 cron.yaml
@@ -8,4 +8,6 @@ cron:
8 8 - description: remind people about their event
9 9 url: /reminder
10 10 schedule: every 20 minutes
11   -
  11 +- description: cache dojo domain stuff
  12 + url: /domaincache
  13 + schedule: every 1 hours
8 main.py
@@ -11,9 +11,14 @@
11 11 from datetime import datetime, timedelta
12 12
13 13 from models import Event, Feedback, ROOM_OPTIONS, PENDING_LIFETIME
14   -from utils import username, human_username, set_cookie, local_today, is_phone_valid, UserRights
  14 +from utils import username, human_username, set_cookie, local_today, is_phone_valid, UserRights, dojo
15 15 from notices import *
16 16
  17 +class DomainCacheCron(webapp.RequestHandler):
  18 + def post(self):
  19 + noop = dojo('/groups/events',force=True)
  20 +
  21 +
17 22 class ReminderCron(webapp.RequestHandler):
18 23 def post(self):
19 24 self.response.out.write("REMINDERS")
@@ -285,6 +290,7 @@ def main():
285 290 ('/event/(\d+)\.json', EventHandler),
286 291 ('/expire', ExpireCron),
287 292 ('/expiring', ExpireReminderCron),
  293 + ('/domaincache', DomainCacheCron),
288 294 ('/reminder', ReminderCron),
289 295 ('/feedback/new/(\d+).*', FeedbackHandler) ],debug=True)
290 296 util.run_wsgi_app(application)
6 utils.py
@@ -7,11 +7,11 @@
7 7 LOCAL_TZ = 'America/Los_Angeles'
8 8
9 9 # Hacker Dojo Domain API helper with caching
10   -def dojo(path):
  10 +def dojo(path,force):
11 11 base_url = 'http://domain.hackerdojo.com'
12 12 cache_ttl = 3600
13 13 resp = memcache.get(path)
14   - if not resp:
  14 + if force or not resp:
15 15 resp = urlfetch.fetch(base_url + path, deadline=10)
16 16 try:
17 17 resp = simplejson.loads(resp.content)
@@ -105,7 +105,7 @@ def __init__(self, user=None, event=None):
105 105 self.can_unstaff = False
106 106
107 107 if self.user:
108   - self.is_admin = username(self.user) in dojo('/groups/events')
  108 + self.is_admin = username(self.user) in dojo('/groups/events',force=False)
109 109 if self.event:
110 110 self.is_owner = (self.user == self.event.member)
111 111 self.can_approve = (self.event.status in ['pending'] and self.is_admin

0 comments on commit 219203b

Please sign in to comment.
Something went wrong with that request. Please try again.