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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import datetime 5 import datetime
6 import itertools 6 import itertools
7 import json 7 import json
8 import logging 8 import logging
9 import urlparse 9 import urlparse
10 10
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ) 128 )
129 if lease_expiration_date is not None: 129 if lease_expiration_date is not None:
130 build.lease_expiration_date = lease_expiration_date 130 build.lease_expiration_date = lease_expiration_date
131 build.leasee = auth.get_current_identity() 131 build.leasee = auth.get_current_identity()
132 build.regenerate_lease_key() 132 build.regenerate_lease_key()
133 build.put() 133 build.put()
134 logging.info( 134 logging.info(
135 'Build %s was created by %s', build.key.id(), identity.to_bytes()) 135 'Build %s was created by %s', build.key.id(), identity.to_bytes())
136 return build 136 return build
137 137
138 @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.
139 def add_batch(self, build_params):
140 """Adds multiple builds in a cross-group transaction.
141
142 Args:
143 build_params: list of dicts, where each dict contains parameters for
144 add() method.
145
146 Returns:
147 List of builds.
148 """
149 if len(build_params) > 25:
150 # Cross-group transactions support up to 25 entity groups.
151 raise errors.InvalidInputError('Cannot add more than 25 builds at a time')
152 builds = []
153 for i, req in enumerate(build_params):
154 try:
155 builds.append(self.add(**req))
156 except errors.Error as ex:
157 msg = 'Error in build request %d: %s' % (i, ex.message)
158 raise type(ex)(msg)
159 return builds
160
138 def get(self, build_id): 161 def get(self, build_id):
139 """Gets a build by |build_id|. 162 """Gets a build by |build_id|.
140 163
141 Requires the current user to have permissions to view the build. 164 Requires the current user to have permissions to view the build.
142 """ 165 """
143 build = model.Build.get_by_id(build_id) 166 build = model.Build.get_by_id(build_id)
144 if not build: 167 if not build:
145 return None 168 return None
146 identity = auth.get_current_identity() 169 identity = auth.get_current_identity()
147 if not acl.can_view_build(build, identity): 170 if not acl.can_view_build(build, identity):
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 628
606 def reset_expired_builds(self): 629 def reset_expired_builds(self):
607 """For all building expired builds, resets their lease_key and state.""" 630 """For all building expired builds, resets their lease_key and state."""
608 q = model.Build.query( 631 q = model.Build.query(
609 model.Build.is_leased == True, 632 model.Build.is_leased == True,
610 model.Build.lease_expiration_date <= datetime.datetime.utcnow(), 633 model.Build.lease_expiration_date <= datetime.datetime.utcnow(),
611 ) 634 )
612 for key in q.iter(keys_only=True): 635 for key in q.iter(keys_only=True):
613 if self._reset_expired_build(key): # pragma: no branch 636 if self._reset_expired_build(key): # pragma: no branch
614 logging.info('Expired build %s was reset' % key.id()) 637 logging.info('Expired build %s was reset' % key.id())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698