add "incomplete" alert boxes
[arvados.git] / services / api / app / controllers / orvos / v1 / jobs_controller.rb
1 class Orvos::V1::JobsController < ApplicationController
2   accept_attribute_as_json :script_parameters, Hash
3   accept_attribute_as_json :resource_limits, Hash
4   accept_attribute_as_json :tasks_summary, Hash
5
6   def index
7     want_ancestor = @where[:script_version_descends_from]
8     if want_ancestor
9       # Check for missing commit_ancestor rows, and create them if
10       # possible.
11       @objects.
12         dup.
13         includes(:commit_ancestors). # I wish Rails would let me
14                                      # specify here which
15                                      # commit_ancestors I am
16                                      # interested in.
17         each do |o|
18         if o.commit_ancestors.
19             select { |ca| ca.ancestor == want_ancestor }.
20             empty? and !o.script_version.nil?
21           begin
22             o.commit_ancestors << CommitAncestor.find_or_create_by_descendant_and_ancestor(o.script_version, want_ancestor)
23           rescue
24           end
25         end
26         o.commit_ancestors.
27           select { |ca| ca.ancestor == want_ancestor }.
28           select(&:is).
29           first
30       end
31       # Now it is safe to do an .includes().where() because we are no
32       # longer interested in jobs that have other ancestors but not
33       # want_ancestor.
34       @objects = @objects.
35         includes(:commit_ancestors).
36         where('commit_ancestors.ancestor = ? and commit_ancestors.is = ?',
37               want_ancestor, true)
38     end
39     super
40   end
41 end