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