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

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

Issue 2090453002: swarmbucket: extend lease to include execution timeout (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: remove extra_time Created 4 years, 6 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 | « no previous file | no next file » | 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 """This module integrates buildbucket with swarming. 5 """This module integrates buildbucket with swarming.
6 6
7 A bucket config may have "swarming" field that specifies how a builder 7 A bucket config may have "swarming" field that specifies how a builder
8 is mapped to a recipe. If build is scheduled for a bucket/builder 8 is mapped to a recipe. If build is scheduled for a bucket/builder
9 with swarming configuration, the integration overrides the default behavior. 9 with swarming configuration, the integration overrides the default behavior.
10 10
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 'swarming_task_id:%s' % task_id, 297 'swarming_task_id:%s' % task_id,
298 ]) 298 ])
299 task_req = res.get('request', {}) 299 task_req = res.get('request', {})
300 for t in task_req.get('tags', []): 300 for t in task_req.get('tags', []):
301 build.tags.append('swarming_tag:%s' % t) 301 build.tags.append('swarming_tag:%s' % t)
302 for d in task_req.get('properties', {}).get('dimensions', []): 302 for d in task_req.get('properties', {}).get('dimensions', []):
303 build.tags.append('swarming_dimension:%s:%s' % (d['key'], d['value'])) 303 build.tags.append('swarming_dimension:%s:%s' % (d['key'], d['value']))
304 304
305 # Mark the build as leased. 305 # Mark the build as leased.
306 assert 'expiration_secs' in task, task 306 assert 'expiration_secs' in task, task
307 # task['expiration_secs'] is max time for the task to be pending
307 task_expiration = datetime.timedelta(seconds=int(task['expiration_secs'])) 308 task_expiration = datetime.timedelta(seconds=int(task['expiration_secs']))
308 extra_time = datetime.timedelta(hours=1) 309 # task['execution_timeout_secs'] is max time for the task to run
309 build.lease_expiration_date = utils.utcnow() + task_expiration + extra_time 310 task_expiration += datetime.timedelta(
311 seconds=int(task['properties']['execution_timeout_secs']))
312 task_expiration += datetime.timedelta(hours=1)
313 build.lease_expiration_date = utils.utcnow() + task_expiration
310 build.regenerate_lease_key() 314 build.regenerate_lease_key()
311 build.leasee = _self_identity() 315 build.leasee = _self_identity()
312 build.never_leased = False 316 build.never_leased = False
313 317
314 # Make it STARTED right away 318 # Make it STARTED right away
315 # because swarming does not notify on task start. 319 # because swarming does not notify on task start.
316 build.status = model.BuildStatus.STARTED 320 build.status = model.BuildStatus.STARTED
317 url_format = bucket_cfg.swarming.url_format or DEFAULT_URL_FORMAT 321 url_format = bucket_cfg.swarming.url_format or DEFAULT_URL_FORMAT
318 build.url = url_format.format( 322 build.url = url_format.format(
319 swarming_hostname=bucket_cfg.swarming.hostname, 323 swarming_hostname=bucket_cfg.swarming.hostname,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 def _extend_unique(target, items): 630 def _extend_unique(target, items):
627 for x in items: 631 for x in items:
628 if x not in target: # pragma: no branch 632 if x not in target: # pragma: no branch
629 target.append(x) 633 target.append(x)
630 634
631 635
632 class TaskToken(tokens.TokenKind): 636 class TaskToken(tokens.TokenKind):
633 expiration_sec = 60 * 60 * 24 # 24 hours. 637 expiration_sec = 60 * 60 * 24 # 24 hours.
634 secret_key = auth.SecretKey('swarming_task_token', scope='local') 638 secret_key = auth.SecretKey('swarming_task_token', scope='local')
635 version = 1 639 version = 1
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698