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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 p._pre_put_hook() | 326 p._pre_put_hook() |
327 if not p.path: | 327 if not p.path: |
328 raise datastore_errors.BadValueError( | 328 raise datastore_errors.BadValueError( |
329 'package %s:%s: path is required' % (p.package_name, p.version)) | 329 'package %s:%s: path is required' % (p.package_name, p.version)) |
330 if p.package_name in package_names: | 330 if p.package_name in package_names: |
331 raise datastore_errors.BadValueError( | 331 raise datastore_errors.BadValueError( |
332 'package %s is specified more than once' % p.package_name) | 332 'package %s is specified more than once' % p.package_name) |
333 package_names.add(p.package_name) | 333 package_names.add(p.package_name) |
334 self.packages.sort(key=lambda p: p.package_name) | 334 self.packages.sort(key=lambda p: p.package_name) |
335 | 335 |
336 def packages_grouped_by_path(self): | |
337 """Returns sorted [(path), [package]) list. Used by user_task.html.""" | |
338 packages = collections.defaultdict(list) | |
339 for p in self.packages: | |
340 packages[p.path].append(p) | |
341 for pkgs in packages.itervalues(): | |
342 pkgs.sort() | |
343 return sorted(packages.iteritems()) | |
344 | |
345 | 336 |
346 class TaskProperties(ndb.Model): | 337 class TaskProperties(ndb.Model): |
347 """Defines all the properties of a task to be run on the Swarming | 338 """Defines all the properties of a task to be run on the Swarming |
348 infrastructure. | 339 infrastructure. |
349 | 340 |
350 This entity is not saved in the DB as a standalone entity, instead it is | 341 This entity is not saved in the DB as a standalone entity, instead it is |
351 embedded in a TaskRequest. | 342 embedded in a TaskRequest. |
352 | 343 |
353 This model is immutable. | 344 This model is immutable. |
354 | 345 |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 init_new_request(request, allow_high_priority) | 783 init_new_request(request, allow_high_priority) |
793 return request | 784 return request |
794 | 785 |
795 | 786 |
796 def validate_priority(priority): | 787 def validate_priority(priority): |
797 """Throws ValueError if priority is not a valid value.""" | 788 """Throws ValueError if priority is not a valid value.""" |
798 if 0 > priority or MAXIMUM_PRIORITY < priority: | 789 if 0 > priority or MAXIMUM_PRIORITY < priority: |
799 raise datastore_errors.BadValueError( | 790 raise datastore_errors.BadValueError( |
800 'priority (%d) must be between 0 and %d (inclusive)' % | 791 'priority (%d) must be between 0 and %d (inclusive)' % |
801 (priority, MAXIMUM_PRIORITY)) | 792 (priority, MAXIMUM_PRIORITY)) |
OLD | NEW |