Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(936)

Side by Side Diff: Tools/GardeningServer/alerts.py

Issue 465233002: Store alerts in sheriff-o-matic's memcache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Feedback, use underscores in method names. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Tools/GardeningServer/alerts_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import calendar
6 import datetime
7 import json
8 import webapp2
9
10 from google.appengine.api import memcache
11
12
13 class DateTimeEncoder(json.JSONEncoder):
14 def default(self, obj):
15 if isinstance(obj, datetime.datetime):
16 return calendar.timegm(obj.timetuple())
17 # Let the base class default method raise the TypeError
18 return json.JSONEncoder.default(self, obj)
19
20
21 class AlertsHandler(webapp2.RequestHandler):
22 MEMCACHE_ALERTS_KEY = 'alerts'
23
24 def get(self):
25 self.response.headers.add_header('Access-Control-Allow-Origin', '*')
26 self.response.headers['Content-Type'] = 'application/json'
27 alerts = memcache.get(AlertsHandler.MEMCACHE_ALERTS_KEY)
28 if not alerts:
29 return
30 self.response.write(json.dumps(alerts, cls=DateTimeEncoder, indent=1))
31
32 def post(self):
33 try:
34 alerts = json.loads(self.request.get('content'))
35 except ValueError:
36 self.response.set_status(400, 'content field was not JSON')
37 return
38 alerts.update({
39 'date': datetime.datetime.utcnow(),
40 'alerts': alerts['alerts']})
ojan 2014/08/13 06:13:24 Bikeshed nit: I'd add a newline before the }
41 memcache.set(AlertsHandler.MEMCACHE_ALERTS_KEY, alerts)
42
43
44 app = webapp2.WSGIApplication([
45 ('/alerts', AlertsHandler)])
ojan 2014/08/13 06:13:25 Ditto nit: newline before the ]
OLDNEW
« no previous file with comments | « no previous file | Tools/GardeningServer/alerts_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698