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

Side by Side Diff: appengine/cr-buildbucket/service.py

Issue 2170673002: buildbucket: add longest_pending_time API (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: nits Created 4 years, 5 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
« no previous file with comments | « appengine/cr-buildbucket/index.yaml ('k') | appengine/cr-buildbucket/test/api_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 contextlib 5 import contextlib
6 import datetime 6 import datetime
7 import logging 7 import logging
8 import urlparse 8 import urlparse
9 9
10 from google.appengine.api import taskqueue 10 from google.appengine.api import taskqueue
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 if isinstance(identity, basestring): 826 if isinstance(identity, basestring):
827 if not identity: # pragma: no cover 827 if not identity: # pragma: no cover
828 return None 828 return None
829 if ':' not in identity: # pragma: no branch 829 if ':' not in identity: # pragma: no branch
830 identity = 'user:%s' % identity 830 identity = 'user:%s' % identity
831 try: 831 try:
832 identity = auth.Identity.from_bytes(identity) 832 identity = auth.Identity.from_bytes(identity)
833 except ValueError as ex: 833 except ValueError as ex:
834 raise errors.InvalidInputError('Invalid identity identity: %s' % ex) 834 raise errors.InvalidInputError('Invalid identity identity: %s' % ex)
835 return identity 835 return identity
836
837
838 def longest_pending_time(bucket, builder):
839 """Returns longest waiting time among SCHEDULED builds of a builder.
840
841 |builder| is a value of "builder" tag.
842
843 Returns a datetime.timedelta.
844 """
845 if not bucket:
846 raise errors.InvalidInputError('no bucket')
847 if not acl.can_access_bucket(bucket):
848 raise acl.current_identity_cannot('access bucket %s', bucket)
849 if not builder:
850 raise errors.InvalidInputError('no builder')
851
852 # Find the oldest, still SCHEDULED build in this builder.
853 q = model.Build.query(
854 model.Build.bucket == bucket,
855 model.Build.tags == ('builder:%s' % builder),
856 model.Build.status == model.BuildStatus.SCHEDULED,
857 projection=[model.Build.create_time])
858 q = q.order(model.Build.create_time)
859 result = q.fetch(1)
860 if not result:
861 return datetime.timedelta(0)
862 return utils.utcnow() - result[0].create_time
OLDNEW
« no previous file with comments | « appengine/cr-buildbucket/index.yaml ('k') | appengine/cr-buildbucket/test/api_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698