OLD | NEW |
---|---|
1 # coding: utf-8 | 1 # coding: utf-8 |
2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 """Tasks definition. | 6 """Tasks definition. |
7 | 7 |
8 Each user request creates a new TaskRequest. The TaskRequest instance saves the | 8 Each user request creates a new TaskRequest. The TaskRequest instance saves the |
9 metadata of the request, e.g. who requested it, when why, etc. It links to the | 9 metadata of the request, e.g. who requested it, when why, etc. It links to the |
10 actual data of the request in a TaskProperties. The TaskProperties represents | 10 actual data of the request in a TaskProperties. The TaskProperties represents |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 from server import config | 68 from server import config |
69 from server import task_pack | 69 from server import task_pack |
70 import acl | 70 import acl |
71 import cipd | 71 import cipd |
72 | 72 |
73 | 73 |
74 # Maximum acceptable priority value, which is effectively the lowest priority. | 74 # Maximum acceptable priority value, which is effectively the lowest priority. |
75 MAXIMUM_PRIORITY = 255 | 75 MAXIMUM_PRIORITY = 255 |
76 | 76 |
77 | 77 |
78 # One day in seconds. Add 10s to account for small jitter. | 78 # Three days in seconds. Add 10s to account for small jitter. |
79 _ONE_DAY_SECS = 24*60*60 + 10 | 79 _THREE_DAY_SECS = 3*24*60*60 + 10 |
80 | 80 |
81 | 81 |
82 # Seven day in seconds. Add 10s to account for small jitter. | 82 # Seven day in seconds. Add 10s to account for small jitter. |
83 _SEVEN_DAYS_SECS = 7*24*60*60 + 10 | 83 _SEVEN_DAYS_SECS = 7*24*60*60 + 10 |
84 | 84 |
85 | 85 |
86 # Minimum value for timeouts. | 86 # Minimum value for timeouts. |
87 _MIN_TIMEOUT_SECS = 1 if utils.is_local_dev_server() else 30 | 87 _MIN_TIMEOUT_SECS = 1 if utils.is_local_dev_server() else 30 |
88 | 88 |
89 | 89 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 def _validate_task_run_id(_prop, value): | 220 def _validate_task_run_id(_prop, value): |
221 """Validates a task_id looks valid without fetching the entity.""" | 221 """Validates a task_id looks valid without fetching the entity.""" |
222 if not value: | 222 if not value: |
223 return None | 223 return None |
224 task_pack.unpack_run_result_key(value) | 224 task_pack.unpack_run_result_key(value) |
225 return value | 225 return value |
226 | 226 |
227 | 227 |
228 def _validate_timeout(prop, value): | 228 def _validate_timeout(prop, value): |
229 """Validates timeouts in seconds in TaskProperties.""" | 229 """Validates timeouts in seconds in TaskProperties.""" |
230 if value and not (_MIN_TIMEOUT_SECS <= value <= _ONE_DAY_SECS): | 230 if value and not (_MIN_TIMEOUT_SECS <= value <= _THREE_DAY_SECS): |
231 # pylint: disable=W0212 | 231 # pylint: disable=W0212 |
232 raise datastore_errors.BadValueError( | 232 raise datastore_errors.BadValueError( |
233 '%s (%ds) must be 0 or between %ds and one day' % | 233 '%s (%ds) must be 0 or between %ds and one day' % |
M-A Ruel
2017/07/21 14:35:56
update
| |
234 (prop._name, value, _MIN_TIMEOUT_SECS)) | 234 (prop._name, value, _MIN_TIMEOUT_SECS)) |
235 | 235 |
236 | 236 |
237 def _validate_tags(prop, value): | 237 def _validate_tags(prop, value): |
238 """Validates TaskRequest.tags.""" | 238 """Validates TaskRequest.tags.""" |
239 _validate_length(prop, value, 1024) | 239 _validate_length(prop, value, 1024) |
240 if ':' not in value: | 240 if ':' not in value: |
241 # pylint: disable=W0212 | 241 # pylint: disable=W0212 |
242 raise datastore_errors.BadValueError( | 242 raise datastore_errors.BadValueError( |
243 '%s must be key:value form, not %s' % (prop._name, value)) | 243 '%s must be key:value form, not %s' % (prop._name, value)) |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 init_new_request(request, allow_high_priority, original_secret_bytes) | 1014 init_new_request(request, allow_high_priority, original_secret_bytes) |
1015 return request | 1015 return request |
1016 | 1016 |
1017 | 1017 |
1018 def validate_priority(priority): | 1018 def validate_priority(priority): |
1019 """Throws ValueError if priority is not a valid value.""" | 1019 """Throws ValueError if priority is not a valid value.""" |
1020 if 0 > priority or MAXIMUM_PRIORITY < priority: | 1020 if 0 > priority or MAXIMUM_PRIORITY < priority: |
1021 raise datastore_errors.BadValueError( | 1021 raise datastore_errors.BadValueError( |
1022 'priority (%d) must be between 0 and %d (inclusive)' % | 1022 'priority (%d) must be between 0 and %d (inclusive)' % |
1023 (priority, MAXIMUM_PRIORITY)) | 1023 (priority, MAXIMUM_PRIORITY)) |
OLD | NEW |