Chromium Code Reviews| 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|. |