Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 functools | 6 import functools |
| 7 | 7 |
| 8 from recipe_engine.types import freeze | 8 from recipe_engine.types import freeze |
| 9 from recipe_engine import recipe_api | 9 from recipe_engine import recipe_api |
| 10 | 10 |
| 11 | 11 |
| 12 # Minimally supported version of swarming.py script (reported by --version). | 12 # Minimally supported version of swarming.py script (reported by --version). |
| 13 MINIMAL_SWARMING_VERSION = (0, 4, 10) | 13 MINIMAL_SWARMING_VERSION = (0, 4, 10) |
| 14 | 14 |
| 15 NAMED_PRIORITIES = { | |
|
M-A Ruel
2016/03/23 12:55:32
I wonder if it should go in chromium_tests or here
Sergiy Byelozyorov
2016/03/23 13:58:53
I don't have a strong preference. But if it goes t
| |
| 16 'min': 1, # higest possible priority | |
|
M-A Ruel
2016/03/23 12:55:32
The infrastructure should never use anything below
Sergiy Byelozyorov
2016/03/23 13:58:53
Done. Note that this also changes the logic of the
| |
| 17 'higher': 25, # used by most masters | |
| 18 'normal': 30, # used by CQ | |
| 19 'lower': 35, # used by chromium.fyi | |
| 20 'default': 200, # very low, should be increased depending on the type of task | |
| 21 'max': 255, # lowest possible priority | |
|
M-A Ruel
2016/03/23 12:55:31
You should use 'highest' and 'lowest' to reduce co
Sergiy Byelozyorov
2016/03/23 13:58:53
Done.
| |
| 22 } | |
| 23 | |
| 15 | 24 |
| 16 def parse_time(value): | 25 def parse_time(value): |
| 17 """Converts serialized time from the API to datetime.datetime.""" | 26 """Converts serialized time from the API to datetime.datetime.""" |
| 18 # When microseconds are 0, the '.123456' suffix is elided. This means the | 27 # When microseconds are 0, the '.123456' suffix is elided. This means the |
| 19 # serialized format is not consistent, which confuses the hell out of python. | 28 # serialized format is not consistent, which confuses the hell out of python. |
| 20 # TODO(maruel): Remove third format once we enforce version >=0.8.2. | 29 # TODO(maruel): Remove third format once we enforce version >=0.8.2. |
| 21 for fmt in ('%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'): | 30 for fmt in ('%Y-%m-%dT%H:%M:%S.%f', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'): |
| 22 try: | 31 try: |
| 23 return datetime.datetime.strptime(value, fmt) | 32 return datetime.datetime.strptime(value, fmt) |
| 24 except ValueError: # pragma: no cover | 33 except ValueError: # pragma: no cover |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 self._default_dimensions = { | 105 self._default_dimensions = { |
| 97 'cpu': 'x86-64', | 106 'cpu': 'x86-64', |
| 98 'gpu': 'none', | 107 'gpu': 'none', |
| 99 } | 108 } |
| 100 # Expirations are set to mildly good values and will be tightened soon. | 109 # Expirations are set to mildly good values and will be tightened soon. |
| 101 self._default_expiration = 60*60 | 110 self._default_expiration = 60*60 |
| 102 self._default_env = {} | 111 self._default_env = {} |
| 103 self._default_hard_timeout = 60*60 | 112 self._default_hard_timeout = 60*60 |
| 104 self._default_idempotent = False | 113 self._default_idempotent = False |
| 105 self._default_io_timeout = 20*60 | 114 self._default_io_timeout = 20*60 |
| 106 # The default priority is extremely low and should be increased dependending | 115 self._default_priority = NAMED_PRIORITIES['default'] |
| 107 # on the type of task. | |
| 108 self._default_priority = 200 | |
| 109 self._default_tags = set() | 116 self._default_tags = set() |
| 110 self._default_user = None | 117 self._default_user = None |
| 111 self._pending_tasks = set() | 118 self._pending_tasks = set() |
| 112 self._show_isolated_out_in_collect_step = True | 119 self._show_isolated_out_in_collect_step = True |
| 113 self._show_shards_in_collect_step = False | 120 self._show_shards_in_collect_step = False |
| 114 self._swarming_server = 'https://chromium-swarm.appspot.com' | 121 self._swarming_server = 'https://chromium-swarm.appspot.com' |
| 115 self._verbose = False | 122 self._verbose = False |
| 116 | 123 |
| 117 @property | 124 @property |
| 118 def swarming_server(self): | 125 def swarming_server(self): |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 276 |
| 270 Priority ranges from 1 to 255. The lower the value, the most important the | 277 Priority ranges from 1 to 255. The lower the value, the most important the |
| 271 task is and will preempty any task with a lower priority. | 278 task is and will preempty any task with a lower priority. |
| 272 | 279 |
| 273 This value can be changed per individual task. | 280 This value can be changed per individual task. |
| 274 """ | 281 """ |
| 275 return self._default_priority | 282 return self._default_priority |
| 276 | 283 |
| 277 @default_priority.setter | 284 @default_priority.setter |
| 278 def default_priority(self, value): | 285 def default_priority(self, value): |
| 279 assert 1 <= value <= 255 | 286 assert NAMED_PRIORITIES['min'] <= value <= NAMED_PRIORITIES['max'] |
| 280 self._default_priority = value | 287 self._default_priority = value |
| 281 | 288 |
| 282 def add_default_tag(self, tag): | 289 def add_default_tag(self, tag): |
| 283 """Adds a tag to the Swarming tasks triggered. | 290 """Adds a tag to the Swarming tasks triggered. |
| 284 | 291 |
| 285 Tags are used for maintenance, they can be used to calculate the number of | 292 Tags are used for maintenance, they can be used to calculate the number of |
| 286 tasks run for a day to calculate the cost of a type of type (CQ, ASAN, etc). | 293 tasks run for a day to calculate the cost of a type of type (CQ, ASAN, etc). |
| 287 | 294 |
| 288 Tags can be added per individual task. | 295 Tags can be added per individual task. |
| 289 """ | 296 """ |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 | 581 |
| 575 Deprecated, to be removed soon. Use 'collect_task' in a loop instead, | 582 Deprecated, to be removed soon. Use 'collect_task' in a loop instead, |
| 576 properly handling exceptions. This method doesn't handle collect failures | 583 properly handling exceptions. This method doesn't handle collect failures |
| 577 well (it aborts on a first failure). | 584 well (it aborts on a first failure). |
| 578 """ | 585 """ |
| 579 return [self.collect_task(t, **kwargs) for t in tasks] | 586 return [self.collect_task(t, **kwargs) for t in tasks] |
| 580 | 587 |
| 581 # To keep compatibility with some build_internal code. To be removed as well. | 588 # To keep compatibility with some build_internal code. To be removed as well. |
| 582 collect_each = collect | 589 collect_each = collect |
| 583 | 590 |
| 591 def parse_priority_adjustment(self, adjustment): | |
| 592 if isinstance(adjustment, basestring) and adjustment in NAMED_PRIORITIES: | |
| 593 return NAMED_PRIORITIES[adjustment] | |
| 594 | |
| 595 try: | |
| 596 return int(adjustment) | |
|
M-A Ruel
2016/03/23 12:55:31
I prefer to not support that and just use names fo
Sergiy Byelozyorov
2016/03/23 13:58:53
Done.
| |
| 597 except (ValueError, TypeError): | |
| 598 return None | |
| 599 | |
| 584 @staticmethod | 600 @staticmethod |
| 585 def _display_pending(summary_json, step_presentation): | 601 def _display_pending(summary_json, step_presentation): |
| 586 """Shows max pending time in seconds across all shards if it exceeds 10s.""" | 602 """Shows max pending time in seconds across all shards if it exceeds 10s.""" |
| 587 pending_times = [ | 603 pending_times = [ |
| 588 (parse_time(shard['started_ts']) - | 604 (parse_time(shard['started_ts']) - |
| 589 parse_time(shard['created_ts'])).total_seconds() | 605 parse_time(shard['created_ts'])).total_seconds() |
| 590 for shard in summary_json.get('shards', []) if shard.get('started_ts') | 606 for shard in summary_json.get('shards', []) if shard.get('started_ts') |
| 591 ] | 607 ] |
| 592 max_pending = max(pending_times) if pending_times else 0 | 608 max_pending = max(pending_times) if pending_times else 0 |
| 593 | 609 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 | 944 |
| 929 def get_shard_view_url(self, index): | 945 def get_shard_view_url(self, index): |
| 930 """Returns URL of HTML page with shard details or None if not available. | 946 """Returns URL of HTML page with shard details or None if not available. |
| 931 | 947 |
| 932 Works only after the task has been successfully triggered. | 948 Works only after the task has been successfully triggered. |
| 933 """ | 949 """ |
| 934 if self._trigger_output and self._trigger_output.get('tasks'): | 950 if self._trigger_output and self._trigger_output.get('tasks'): |
| 935 for shard_dict in self._trigger_output['tasks'].itervalues(): | 951 for shard_dict in self._trigger_output['tasks'].itervalues(): |
| 936 if shard_dict['shard_index'] == index: | 952 if shard_dict['shard_index'] == index: |
| 937 return shard_dict['view_url'] | 953 return shard_dict['view_url'] |
| OLD | NEW |