3187: Generalized reloading to reload other parts of the page in addition to
[arvados.git] / apps / workbench / app / views / pipeline_instances / _show_components_running.html.erb
1 <%# Summary %>
2
3 <% if @object.state == 'Paused' %>
4   <p>
5     This pipeline is paused.  Jobs that are
6     already running will continue to run, but no new jobs will be submitted.
7   </p>
8 <% end %>
9
10 <p>
11   This pipeline
12   <% if @object.state == 'Complete' %>
13     completed in
14   <% elsif @object.state == 'Failed' %>
15     failed after
16   <% else %>
17     has been active for
18   <% end %>
19   <% walltime = if @object.started_at
20         if @object.finished_at
21           @object.finished_at - @object.started_at
22         else
23           Time.now - @object.started_at
24         end
25       else
26         0
27       end
28       %>
29   <%= runtime(walltime, true) %>, running for
30
31     <% tasks = JobTask.filter([['job_uuid', 'in', render_pipeline_jobs.map { |j| j[:job].andand[:uuid] }]]).results %>
32
33     <%# want to buy: algorithm that calculates wall clock runtime that takes into account
34         concurrent jobs.  %>
35     <% runningtime = determine_wallclock_runtime(render_pipeline_jobs.map {|j| j[:job]}) %>
36
37     <%= runtime(runningtime, true) %><% if tasks.size == 0 %>.<% else %>,
38       using
39       <% cputime = tasks.map { |task|
40            puts "started at #{task.started_at}"
41                   if task.started_at
42                     (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
43                   else
44                     0
45                   end
46                 }.reduce(:+) %>
47     <%= runtime(cputime, true) %>
48     of CPU time (<%= (cputime/runningtime).round(1) %>&Cross; scaling).
49     <% end %>
50 </p>
51
52 <%# Components %>
53
54 <% render_pipeline_jobs.each_index do |i| %>
55   <% pj = render_pipeline_jobs[i] %>
56   <% current_job = pj[:job] if pj[:job] != {} %>
57   <div class="panel panel-default">
58     <div class="panel-heading">
59       <div class="container-fluid">
60         <div class="row">
61           <div class="col-md-3">
62             <h4 class="panel-title">
63               <a data-toggle="collapse" data-parent="#accordion" href="#collapse<%= i %>">
64                 <%= pj[:name] %> <span class="caret"></span>
65               </a>
66             </h4>
67           </div>
68
69           <% puts current_job.inspect %>
70
71           <% if current_job %>
72             <div class="col-md-1">
73               <%= render(partial: 'job_status_label', locals: { j: current_job }) %>
74             </div>
75
76             <div class="col-md-3">
77               <% if current_job[:started_at] %>
78                 <% walltime = ((if current_job.finished_at then current_job.finished_at else Time.now() end) - current_job.started_at) %>
79                 <% cputime = tasks.map { |task|
80                      if task.started_at and task.job_uuid == current_job.uuid
81                        (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
82                      else
83                        0
84                      end
85                    }.reduce(:+) %>
86                 <%= runtime(walltime, false) %> / <%= runtime(cputime, false) %> (<%= (cputime/walltime).round(1) %>&Cross;)
87               <% end %>
88             </div>
89
90             <% if Job::state(current_job).in? ["Completed", "Failed", "Canceled"] %>
91               <div class="col-md-3">
92                 <% if pj[:output_uuid] %>
93                   <%= link_to_if_arvados_object pj[:output_uuid] %>
94                 <% elsif current_job.andand[:output] %>
95                   <%= link_to_if_arvados_object current_job[:output], link_text: "Output of #{pj[:name]}" %>
96                 <% else %>
97                   No output.
98                 <% end %>
99               </div>
100             <% elsif Job::state(current_job) == "Running" %>
101               <div class="col-md-3 pipeline-instance-spacing">
102                 <%= pj[:progress_bar] %>
103               </div>
104               <div class="col-md-1 pipeline-instance-spacing">
105                 <%= form_tag "/jobs/#{current_job.uuid}/cancel", style: "display:inline; padding-left: 1em" do |f| %>
106                 <%= hidden_field_tag :return_to, url_for(@object) %>
107                 <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
108             </div>
109             <% end %>
110           <% elsif Job::state(current_job) == "Queued" %>
111             <div class="col-md-5">
112               <% queuetime = Time.now - current_job[:created_at] %>
113               Queued for <%= runtime(queuetime, true) %>.
114                 There
115               <% if current_job.queue_position == 0 %>
116                 are no jobs
117               <% elsif current_job.queue_position == 1 %>
118                 is 1 job
119               <% else  %>
120                 <%= current_job.queue_position %> jobs
121               <% end %>
122                 ahead of this one.
123             </div>
124           <% end %>
125         <% else %>
126           <div class="col-md-3 col-md-offset-3">
127             <span class="label label-default">Not ready</span>
128           </div>
129 <% end %>
130 </div>
131 </div>
132 </div>
133
134 <div id="collapse<%= i %>" class="panel-collapse collapse in">
135   <div class="panel-body">
136     <div class="container">
137         <% current_component = (if current_job then current_job else pj end) %>
138         <div class="row">
139           <div class="col-md-6">
140             <table>
141               <% [:script, :repository, :supplied_script_version, :script_version, :nondeterministic].each do |k| %>
142                 <tr>
143                   <td style="padding-right: 1em">
144                     <%= k.to_s %>:
145                   </td>
146                   <td>
147                     <%= current_component[k] %>
148                   </td>
149                 </tr>
150               <% end %>
151               <% if current_component[:runtime_constraints].andand[:docker_image] and current_component[:docker_image_locator] %>
152                 <tr>
153                   <td style="padding-right: 1em">
154                     docker_image:
155                   </td>
156                   <td>
157                     <%= current_component[:runtime_constraints][:docker_image] %>
158                   </td>
159                 </tr>
160                 <tr>
161                   <td style="padding-right: 1em">
162                     docker_image_locator:
163                   </td>
164                   <td>
165                     <%= link_to_if_arvados_object current_component[:docker_image_locator] %>
166                   </td>
167                 </tr>
168               <% else %>
169                 <tr>
170                   <td style="padding-right: 1em">
171                     docker_image:
172                   </td>
173                   <td>
174                     Not run in Docker
175                   </td>
176                 </tr>
177               <% end %>
178             </table>
179           </div>
180           <div class="col-md-5">
181             <table>
182               <% [:uuid, :modified_by_user_uuid, :priority, :created_at, :started_at, :finished_at].each do |k| %>
183                 <tr>
184                   <td style="padding-right: 1em">
185                     <%= k.to_s %>:
186                   </td>
187                   <td>
188                     <% if k.to_s.end_with? 'uuid' %>
189                       <%= link_to_if_arvados_object current_component[k], friendly_name: true %>
190                     <% else %>
191                       <%= current_component[k] %>
192                     <% end %>
193                   </td>
194                 </tr>
195               <% end %>
196             </table>
197           </div>
198         </div>
199         <div class="row">
200           <div class="col-md-6">
201             <p>script_parameters:</p>
202             <pre><%= JSON.pretty_generate(current_component[:script_parameters]) rescue nil %></pre>
203           </div>
204           <% if current_component[:tasks_summary] %>
205           <div class="col-md-3">
206             <table>
207               <% [:done, :running, :failed, :todo].each do |d| %>
208               <tr>
209                 <td style="padding-right: 1em"><%= 'tasks:' if d == :done %></td>
210                 <td style="padding-right: 1em"><%= d.to_s %></td>
211                 <td><%= current_component[:tasks_summary][d] %></td>
212               </tr>
213               <% end %>
214             </table>
215           </div>
216           <% end %>
217         </div>
218     </div>
219   </div>
220 </div>
221 </div>
222 <% end %>