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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Tools/GardeningServer/alerts_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/GardeningServer/alerts.py
diff --git a/Tools/GardeningServer/alerts.py b/Tools/GardeningServer/alerts.py
new file mode 100644
index 0000000000000000000000000000000000000000..e9f136f0aab5aa4edd30c01f8640b4fd1969b0c1
--- /dev/null
+++ b/Tools/GardeningServer/alerts.py
@@ -0,0 +1,45 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import calendar
+import datetime
+import json
+import webapp2
+
+from google.appengine.api import memcache
+
+
+class DateTimeEncoder(json.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, datetime.datetime):
+ return calendar.timegm(obj.timetuple())
+ # Let the base class default method raise the TypeError
+ return json.JSONEncoder.default(self, obj)
+
+
+class AlertsHandler(webapp2.RequestHandler):
+ MEMCACHE_ALERTS_KEY = 'alerts'
+
+ def get(self):
+ self.response.headers.add_header('Access-Control-Allow-Origin', '*')
+ self.response.headers['Content-Type'] = 'application/json'
+ alerts = memcache.get(AlertsHandler.MEMCACHE_ALERTS_KEY)
+ if not alerts:
+ return
+ self.response.write(json.dumps(alerts, cls=DateTimeEncoder, indent=1))
+
+ def post(self):
+ try:
+ alerts = json.loads(self.request.get('content'))
+ except ValueError:
+ self.response.set_status(400, 'content field was not JSON')
+ return
+ alerts.update({
+ 'date': datetime.datetime.utcnow(),
+ 'alerts': alerts['alerts']})
ojan 2014/08/13 06:13:24 Bikeshed nit: I'd add a newline before the }
+ memcache.set(AlertsHandler.MEMCACHE_ALERTS_KEY, alerts)
+
+
+app = webapp2.WSGIApplication([
+ ('/alerts', AlertsHandler)])
ojan 2014/08/13 06:13:25 Ditto nit: newline before the ]
« 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