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

Unified Diff: appengine/cr-buildbucket/service.py

Issue 1082303002: buildbucket: put_batch endpoint (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 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: appengine/cr-buildbucket/service.py
diff --git a/appengine/cr-buildbucket/service.py b/appengine/cr-buildbucket/service.py
index 0fcd66fd5548075644b44cd4ba1ea5c838f494ad..bcb17237887120944e713afe76dcd1ce1266caaf 100644
--- a/appengine/cr-buildbucket/service.py
+++ b/appengine/cr-buildbucket/service.py
@@ -135,6 +135,29 @@ class BuildBucketService(object):
'Build %s was created by %s', build.key.id(), identity.to_bytes())
return build
+ @ndb.transactional(xg=True) # pylint: disable=no-value-for-parameter
Vadim Sh. 2015/04/14 18:56:40 I don't think adding them all transactionally is a
nodir 2015/04/14 22:13:05 Done.
+ def add_batch(self, build_params):
+ """Adds multiple builds in a cross-group transaction.
+
+ Args:
+ build_params: list of dicts, where each dict contains parameters for
+ add() method.
+
+ Returns:
+ List of builds.
+ """
+ if len(build_params) > 25:
+ # Cross-group transactions support up to 25 entity groups.
+ raise errors.InvalidInputError('Cannot add more than 25 builds at a time')
+ builds = []
+ for i, req in enumerate(build_params):
+ try:
+ builds.append(self.add(**req))
+ except errors.Error as ex:
+ msg = 'Error in build request %d: %s' % (i, ex.message)
+ raise type(ex)(msg)
+ return builds
+
def get(self, build_id):
"""Gets a build by |build_id|.

Powered by Google App Engine
This is Rietveld 408576698