3187: Lots of work on presentation of job details, calculating time and
[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 = render_pipeline_jobs.map { |j|
36          if j[:job] and j[:job].started_at
37            (if j[:job].finished_at then j[:job].finished_at else Time.now() end) - j[:job].started_at
38          else
39            0
40          end
41        }.reduce(:+) %>
42
43     <%= runtime(runningtime, true) %><% if tasks.size == 0 %>.<% else %>,
44       using
45       <% cputime = tasks.map { |task|
46                   if task.started_at
47                     (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
48                   else
49                     0
50                   end
51                 }.reduce(:+) %>
52     <%= runtime(cputime, true) %>
53     of CPU time (<%= (cputime/runningtime).round(1) %>&Cross; scaling).
54     <% end %>
55 </p>
56
57 <%# Components %>
58
59 <% render_pipeline_jobs.each_index do |i| %>
60   <% pj = render_pipeline_jobs[i] %>
61   <% current_job = pj[:job] if pj[:job] != {} %>
62   <div class="panel panel-default">
63     <div class="panel-heading">
64       <div class="container-fluid">
65         <div class="row">
66           <div class="col-md-3">
67             <h4 class="panel-title">
68               <a data-toggle="collapse" data-parent="#accordion" href="#collapse<%= i %>">
69                 <%= pj[:name] %> <span class="caret"></span>
70               </a>
71             </h4>
72           </div>
73
74           <% puts current_job.inspect %>
75
76           <% if current_job %>
77             <div class="col-md-3">
78               <% if current_job.started_at %>
79                 <% walltime = ((if current_job.finished_at then current_job.finished_at else Time.now() end) - current_job.started_at) %>
80                 <% cputime = tasks.map { |task|
81                      if task.started_at and task.job_uuid == current_job.uuid
82                        (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
83                      else
84                        0
85                      end
86                    }.reduce(:+) %>
87                 <%= runtime(walltime, false) %> / <%= runtime(cputime, false) %> (<%= (cputime/walltime).round(1) %>&Cross;)
88               <% end %>
89             </div>
90
91             <% if current_job.state.in? ["Completed", "Failed", "Canceled"] %>
92               <div class="col-md-3">
93                 <%= render(partial: 'job_status_label', locals: { j: current_job }) %>
94               </div>
95               <div class="col-md-3">
96                 <% if pj[:output_uuid] %>
97                   <%= link_to_if_arvados_object pj[:output_uuid] %>
98                 <% elsif current_job.andand[:output] %>
99                   <%= link_to_if_arvados_object current_job[:output], link_text: "Output of #{pj[:name]}" %>
100                 <% end %>
101               </div>
102             <% elsif current_job.state == "Running" %>
103               <div class="col-md-3">
104                 <%= pj[:progress_bar] %>
105               </div>
106               <div class="col-md-3">
107                 <%= form_tag "/jobs/#{current_job.uuid}/cancel", style: "display:inline; padding-left: 1em" do |f| %>
108                 <%= hidden_field_tag :return_to, url_for(@object) %>
109                 <%= button_tag "Cancel", {class: 'btn btn-danger', id: "cancel-job-button"} %>
110             </div>
111             <% end %>
112           <% elsif current_job.state == "Queued" %>
113             <div class="col-md-1">
114               <span class="label label-default">Queued</span>
115             </div>
116             <div class="col-md-5">
117               <% queuetime = Time.now - current_job.created_at %>
118               Queued for <%= runtime(queuetime, true) %>.
119                 There
120               <% if current_job.queue_position == 0 %>
121                 are no jobs
122               <% elsif current_job.queue_position == 1 %>
123                 is 1 job
124               <% else  %>
125                 <%= current_job.queue_position %> jobs
126               <% end %>
127                 ahead of this one.
128             </div>
129           <% end %>
130         <% else %>
131           <div class="col-md-3 col-md-offset-3">
132             <span class="label label-default">Not ready</span>
133           </div>
134 <% end %>
135 </div>
136 </div>
137 </div>
138
139 <div id="collapse<%= i %>" class="panel-collapse collapse in">
140   <div class="panel-body">
141     <div class="container">
142         <% current_component = (if current_job then current_job else pj end) %>
143         <div class="row">
144           <div class="col-md-6">
145             <table>
146               <% [:script, :repository, :supplied_script_version, :script_version, :nondeterministic].each do |k| %>
147                 <tr>
148                   <td style="padding-right: 1em">
149                     <%= k.to_s %>:
150                   </td>
151                   <td>
152                     <%= current_component[k] %>
153                   </td>
154                 </tr>
155               <% end %>
156               <% if current_component[:runtime_constraints].andand[:docker_image] and current_component[:docker_image_locator] %>
157                 <tr>
158                   <td style="padding-right: 1em">
159                     docker_image:
160                   </td>
161                   <td>
162                     <%= current_component[:runtime_constraints][:docker_image] %>
163                   </td>
164                 </tr>
165                 <tr>
166                   <td style="padding-right: 1em">
167                     docker_image_locator:
168                   </td>
169                   <td>
170                     <%= link_to_if_arvados_object current_component[:docker_image_locator] %>
171                   </td>
172                 </tr>
173               <% else %>
174                 <tr>
175                   <td style="padding-right: 1em">
176                     docker_image:
177                   </td>
178                   <td>
179                     Not run in Docker
180                   </td>
181                 </tr>
182               <% end %>
183             </table>
184           </div>
185           <div class="col-md-5">
186             <table>
187               <% [:uuid, :modified_by_user_uuid, :priority, :created_at, :started_at, :finished_at].each do |k| %>
188                 <tr>
189                   <td style="padding-right: 1em">
190                     <%= k.to_s %>:
191                   </td>
192                   <td>
193                     <% if k.to_s.end_with? 'uuid' %>
194                       <%= link_to_if_arvados_object current_component[k], friendly_name: true %>
195                     <% else %>
196                       <%= current_component[k] %>
197                     <% end %>
198                   </td>
199                 </tr>
200               <% end %>
201             </table>
202           </div>
203         </div>
204         <div class="row">
205           <div class="col-md-6">
206             <p>script_parameters:</p>
207             <pre><%= JSON.pretty_generate(current_component[:script_parameters]) rescue nil %></pre>
208           </div>
209           <% if current_component[:tasks_summary] %>
210           <div class="col-md-3">
211             <table>
212               <% [:done, :running, :failed, :todo].each do |d| %>
213               <tr>
214                 <td style="padding-right: 1em"><%= 'tasks:' if d == :done %></td>
215                 <td style="padding-right: 1em"><%= d.to_s %></td>
216                 <td><%= current_component[:tasks_summary][d] %></td>
217               </tr>
218               <% end %>
219             </table>
220           </div>
221           <% end %>
222         </div>
223     </div>
224   </div>
225 </div>
226 </div>
227 <% end %>