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

Unified Diff: chrome/common/extensions/docs/server2/persistent_object_store.py

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integration test Created 7 years, 8 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
Index: chrome/common/extensions/docs/server2/persistent_object_store.py
diff --git a/chrome/common/extensions/docs/server2/persistent_object_store.py b/chrome/common/extensions/docs/server2/persistent_object_store.py
new file mode 100644
index 0000000000000000000000000000000000000000..853b660eaf921dab8a9c6c22ba6dfe290ae2450d
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/persistent_object_store.py
@@ -0,0 +1,50 @@
+# Copyright 2013 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.
+
+from appengine_wrappers import db, IsDevServer
+from datastore_models import PersistentObjectStoreItem
+from future import Future
+import logging
+from object_store import ObjectStore
+
+class _AsyncGetFuture(object):
+ def __init__(self, object_store, keys):
+ self._futures = dict(
+ (k, db.get_async(
+ PersistentObjectStoreItem.CreateKey(object_store._namespace, k)))
+ for k in keys)
+
+ def Get(self):
+ return dict((key, future.get_result().GetValue())
+ for key, future in self._futures.iteritems()
+ if future.get_result() is not None)
+
+class PersistentObjectStore(ObjectStore):
+ '''Stores data persistently using the AppEngine Datastore API.
+ '''
+ def __init__(self, namespace):
+ self._namespace = namespace
+
+ def SetMulti(self, mapping):
+ futures = []
+ for key, value in mapping.items():
+ futures.append(db.put_async(
+ PersistentObjectStoreItem.CreateItem(self._namespace, key, value)))
+ # If running the dev server, the futures don't complete until the server is
+ # *quitting*. This is annoying. Flush now.
+ if IsDevServer():
+ [future.wait() for future in futures]
+
+ def GetMulti(self, keys):
+ return Future(delegate=_AsyncGetFuture(self, keys))
+
+ def DelMulti(self, keys):
+ futures = []
+ for key in keys:
+ futures.append(db.delete_async(
+ PersistentObjectStoreItem.CreateKey(self._namespace, key)))
+ # If running the dev server, the futures don't complete until the server is
+ # *quitting*. This is annoying. Flush now.
+ if IsDevServer():
+ [future.wait() for future in futures]

Powered by Google App Engine
This is Rietveld 408576698