Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / controllers / jobs_controller.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class JobsController < ApplicationController
6   skip_around_action :require_thread_api_token, if: proc { |ctrl|
7     !Rails.configuration.Users.AnonymousUserToken.empty? and
8     'show' == ctrl.action_name
9   }
10
11   def generate_provenance(jobs)
12     return if params['tab_pane'] != "Provenance"
13
14     nodes = {}
15     collections = []
16     hashes = []
17     jobs.each do |j|
18       nodes[j[:uuid]] = j
19       hashes << j[:output]
20       ProvenanceHelper::find_collections(j[:script_parameters]) do |hash, uuid|
21         collections << uuid if uuid
22         hashes << hash if hash
23       end
24       nodes[j[:script_version]] = {:uuid => j[:script_version]}
25     end
26
27     Collection.where(uuid: collections).with_count("none").each do |c|
28       nodes[c[:portable_data_hash]] = c
29     end
30
31     Collection.where(portable_data_hash: hashes).with_count("none").each do |c|
32       nodes[c[:portable_data_hash]] = c
33     end
34
35     @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {
36       :request => request,
37       :all_script_parameters => true,
38       :script_version_nodes => true}
39   end
40
41   def index
42     @svg = ""
43     if params[:uuid]
44       @objects = Job.where(uuid: params[:uuid])
45       generate_provenance(@objects)
46       render_index
47     else
48       @limit = 20
49       super
50     end
51   end
52
53   def cancel
54     @object.cancel
55     if params[:return_to]
56       redirect_to params[:return_to]
57     else
58       redirect_to @object
59     end
60   end
61
62   def show
63     generate_provenance([@object])
64     super
65   end
66
67   def logs
68     @logs = @object.
69       stderr_log_query(Rails.configuration.Workbench.RunningJobLogRecordsToFetch).
70       map { |e| e.serializable_hash.merge({ 'prepend' => true }) }
71     respond_to do |format|
72       format.json { render json: @logs }
73     end
74   end
75
76   def index_pane_list
77     if params[:uuid]
78       %w(Recent Provenance)
79     else
80       %w(Recent)
81     end
82   end
83
84   def show_pane_list
85     %w(Status Log Details Provenance Advanced)
86   end
87 end