3605: Change runtime() to render_runtime(). Improve rendering when started_at
[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   <% if @object.started_at %>
12     This pipeline started at <span data-utc-date="<%= @object.started_at %>"><%= @object.started_at %></span>.
13   <% end %>
14
15   <% if @object.started_at %>
16     This pipeline
17     <% if @object.state == 'Complete' %>
18       completed in
19     <% elsif @object.state == 'Failed' %>
20       failed after
21     <% else %>
22       has been active for
23     <% end %>
24
25     <% walltime = if @object.finished_at then
26                     @object.finished_at - @object.started_at
27                   else
28                     Time.now - @object.started_at
29                   end %>
30     
31     <%= runtime(walltime, true) %><% if @object.finished_at %> at <span data-utc-date="<%= @object.finished_at %>"><%= @object.finished_at %></span><% end %>.
32   <% else %>
33     This pipeline is <%= if @object.state.start_with? 'Running' then 'active' else @object.state.downcase end %>.
34     <% walltime = 0%>
35   <% end %>
36
37   <% if @object.state == 'Failed' %>
38     Check the Log tab for more detail about why this pipeline failed.
39   <% end %>
40 </p>
41
42 <p>
43     <% tasks = JobTask.filter([['job_uuid', 'in', render_pipeline_jobs.map { |j| j[:job].andand[:uuid] }]]).results %>
44     <% runningtime = determine_wallclock_runtime(render_pipeline_jobs.map {|j| j[:job]}) %>
45     It
46     <% if @object.state.start_with? 'Running' %>
47       has run
48     <% else %>
49       ran
50     <% end %>
51     for
52     <%= render_runtime(runningtime, true, false) %><% cputime = tasks.map { |task|
53                   if task.started_at
54                     (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
55                   else
56                     0
57                   end
58                 }.reduce(:+) %><% if walltime - runningtime > 0 %>
59       (<%= render_runtime(walltime - runningtime, true) %> queued)<% end %><% if cputime == 0 %>.<% else %>
60       and used
61     <%= render_runtime(cputime, true) %>
62     of CPU time (<%= (cputime/runningtime).round(1) %>&Cross; scaling).
63     <% end %>
64 </p>
65
66 <%# Components %>
67
68 <% render_pipeline_jobs.each_index do |i| %>
69   <% pj = render_pipeline_jobs[i] %>
70   <% current_job = pj[:job] if pj[:job] != {} %>
71   <div class="panel panel-default">
72     <div class="panel-heading">
73       <div class="container-fluid">
74         <div class="row">
75           <div class="col-md-3">
76             <h4 class="panel-title">
77               <a data-toggle="collapse" href="#collapse<%= i %>">
78                 <%= pj[:name] %> <span class="caret"></span>
79               </a>
80             </h4>
81           </div>
82
83           <% if current_job %>
84             <div class="col-md-1">
85               <%= render(partial: 'job_status_label', locals: { j: current_job }) %>
86             </div>
87
88             <div class="col-md-3">
89               <% if current_job[:started_at] %>
90                 <% walltime = ((if current_job.finished_at then current_job.finished_at else Time.now() end) - current_job.started_at) %>
91                 <% cputime = tasks.map { |task|
92                      if task.started_at and task.job_uuid == current_job.uuid
93                        (if task.finished_at then task.finished_at else Time.now() end) - task.started_at
94                      else
95                        0
96                      end
97                    }.reduce(:+) %>
98                 <%= render_runtime(walltime, false, false) %>
99                 <% if cputime > 0 %> / <%= render_runtime(cputime, false, false) %> (<%= (cputime/walltime).round(1) %>&Cross;)<% end %>
100               <% end %>
101             </div>
102
103             <% if Job::state(current_job).in? ["Completed", "Failed", "Canceled"] %>
104               <div class="col-md-3">
105                 <% if pj[:output_uuid] %>
106                   <%= link_to_if_arvados_object pj[:output_uuid], friendly_name: true %>
107                 <% elsif current_job.andand[:output] %>
108                   <%= link_to_if_arvados_object current_job[:output], link_text: "Output of #{pj[:name]}" %>
109                 <% else %>
110                   No output.
111                 <% end %>
112               </div>
113             <% elsif Job::state(current_job) == "Running" %>
114               <div class="col-md-3 pipeline-instance-spacing">
115                 <%= pj[:progress_bar] %>
116               </div>
117               <div class="col-md-1 pipeline-instance-spacing">
118                 <%= form_tag "/jobs/#{current_job.uuid}/cancel", style: "display:inline; padding-left: 1em" do |f| %>
119                 <%= hidden_field_tag :return_to, url_for(@object) %>
120                 <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
121             </div>
122             <% end %>
123           <% elsif Job::state(current_job) == "Queued" %>
124             <div class="col-md-5">
125               <% queuetime = Time.now - current_job[:created_at] %>
126               Queued for <%= render_runtime(queuetime, true) %>.
127               <% begin %>
128               <% if current_job.queue_position == 0 %>
129                 This job is next in the queue to run.
130               <% elsif current_job.queue_position == 1 %>
131                 There is 1 job in the queue ahead of this one.
132               <% else  %>
133                 There are <%= current_job.queue_position %> jobs in the queue ahead of this one.
134               <% end %>
135               <% rescue %>
136           <% end %>
137             </div>
138           <% end %>
139         <% else %>
140           <div class="col-md-3 col-md-offset-3">
141             <span class="label label-default">Not ready</span>
142           </div>
143 <% end %>
144 </div>
145 </div>
146 </div>
147
148 <div id="collapse<%= i %>" class="panel-collapse collapse">
149   <div class="panel-body">
150     <div class="container">
151         <% current_component = (if current_job then current_job else pj end) %>
152         <div class="row">
153           <div class="col-md-6">
154             <table>
155               <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic].each do |k| %>
156                 <tr>
157                   <td style="padding-right: 1em">
158                     <%= k.to_s %>:
159                   </td>
160                   <td>
161                     <% if current_component[k].nil? %>
162                       (none)
163                     <% else %>
164                       <%= current_component[k] %>
165                     <% end %>
166                   </td>
167                 </tr>
168               <% end %>
169               <% if current_component[:runtime_constraints].andand[:docker_image] and current_component[:docker_image_locator] %>
170                 <tr>
171                   <td style="padding-right: 1em">
172                     docker_image:
173                   </td>
174                   <td>
175                     <%= current_component[:runtime_constraints][:docker_image] %>
176                   </td>
177                 </tr>
178                 <tr>
179                   <td style="padding-right: 1em">
180                     docker_image_locator:
181                   </td>
182                   <td>
183                     <%= link_to_if_arvados_object current_component[:docker_image_locator], friendly_name: true %>
184                   </td>
185                 </tr>
186               <% else %>
187                 <tr>
188                   <td style="padding-right: 1em">
189                     docker_image:
190                   </td>
191                   <td>
192                     Not run in Docker
193                   </td>
194                 </tr>
195               <% end %>
196             </table>
197           </div>
198           <div class="col-md-5">
199             <table>
200               <% [:uuid, :modified_by_user_uuid, :priority, :created_at, :started_at, :finished_at].each do |k| %>
201                 <tr>
202                   <td style="padding-right: 1em">
203                     <%= k.to_s %>:
204                   </td>
205                   <td>
206                     <% if k == :uuid %>
207                       <%= link_to_if_arvados_object current_component[k], link_text: current_component[k] %>
208                     <% elsif k.to_s.end_with? 'uuid' %>
209                       <%= link_to_if_arvados_object current_component[k], friendly_name: true %>
210                     <% elsif k.to_s.end_with? '_at' %>
211                       <span data-utc-date="<%= current_component[k] %>"><%= current_component[k] %></span>
212                     <% else %>
213                       <%= current_component[k] %>
214                     <% end %>
215                   </td>
216                 </tr>
217               <% end %>
218             </table>
219           </div>
220         </div>
221         <div class="row">
222           <div class="col-md-6">
223             <p>script_parameters:</p>
224             <pre><%= JSON.pretty_generate(current_component[:script_parameters]) rescue nil %></pre>
225           </div>
226           <% if current_component[:tasks_summary] %>
227           <div class="col-md-3">
228             <table>
229               <% [:done, :running, :failed, :todo].each do |d| %>
230               <tr>
231                 <td style="padding-right: 1em"><%= 'tasks:' if d == :done %></td>
232                 <td style="padding-right: 1em"><%= d.to_s %></td>
233                 <td><%= current_component[:tasks_summary][d] %></td>
234               </tr>
235               <% end %>
236             </table>
237           </div>
238           <% end %>
239         </div>
240     </div>
241   </div>
242 </div>
243 </div>
244 <% end %>