7753: when a job is in "Running" state, the Log link still should be shown in the...
[arvados.git] / apps / workbench / app / views / pipeline_instances / _running_component.html.erb
1 <% current_job = pj[:job] if pj[:job] != {} and pj[:job][:uuid] %>
2 <div class="panel panel-default">
3   <div class="panel-heading">
4     <div class="container-fluid">
5       <div class="row-fluid">
6         <%# column offset 0 %>
7         <div class="col-md-2" style="word-break:break-all;">
8           <h4 class="panel-title">
9             <a data-toggle="collapse" href="#collapse<%= i %>">
10               <%= pj[:name] %> <span class="caret"></span>
11             </a>
12           </h4>
13         </div>
14
15         <%# column offset 2 %>
16         <div class="col-md-2 pipeline-instance-spacing">
17           <%= pj[:progress_bar] %>
18         </div>
19
20         <% if current_job %>
21           <%# column offset 4 %>
22           <% if current_job[:state].in? ["Complete", "Failed", "Cancelled"] %>
23             <div class="col-md-1">
24             <% if current_job[:log] %>
25                 <% logCollection = Collection.find? current_job[:log] %>
26                 <% if logCollection %>
27                   <%= link_to "Log", job_path(current_job[:uuid], anchor: "Log") %>
28                 <% else %>
29                   Log unavailable
30                 <% end %>
31             <% end %>
32             </div>
33           <% elsif current_job[:state] == "Running" %>
34             <div class="col-md-1">
35               <% job = Job.find? current_job[:uuid] %>
36               <% if job %>
37                 <%= link_to "Log", job_path(current_job[:uuid], anchor: "Log") %>
38               <% else %>
39                 Log unavailable
40               <% end %>
41             </div>
42           <% end %>
43
44           <%# column offset 5 %>
45           <% if current_job[:state] != "Queued" %>
46           <div class="col-md-3">
47             <% if current_job[:started_at] %>
48               <% walltime = ((if current_job[:finished_at] then current_job[:finished_at] else Time.now() end) - current_job[:started_at]) %>
49               <% cputime = (current_job[:runtime_constraints].andand[:min_nodes] || 1) *
50                            ((current_job[:finished_at] || Time.now()) - current_job[:started_at]) %>
51               <%= render_runtime(walltime, false) %>
52               <% if cputime > 0 %> / <%= render_runtime(cputime, false) %> (<%= (cputime/walltime).round(1) %>&Cross;)<% end %>
53             <% end %>
54           </div>
55           <% end %>
56
57           <% if current_job[:state] == "Queued" %>
58             <%# column offset 5 %>
59             <div class="col-md-6">
60               <% queuetime = Time.now - Time.parse(current_job[:created_at].to_s) %>
61               Queued for <%= render_runtime(queuetime, false) %>.
62               <% begin %>
63                 <% if current_job[:queue_position] == 0 %>
64                   This job is next in the queue to run.
65                 <% elsif current_job[:queue_position] == 1 %>
66                   There is 1 job in the queue ahead of this one.
67                 <% elsif current_job[:queue_position] %>
68                   There are <%= current_job[:queue_position] %> jobs in the queue ahead of this one.
69                 <% end %>
70               <% rescue %>
71               <% end %>
72             </div>
73           <% elsif current_job[:state] == "Running" %>
74             <%# column offset 8 %>
75             <div class="col-md-3">
76               <span class="task-summary-status">
77                 <%= current_job[:tasks_summary][:done] %>&nbsp;<%= "task".pluralize(current_job[:tasks_summary][:done]) %> done,
78                 <%= current_job[:tasks_summary][:failed] %>&nbsp;failed,
79                 <%= current_job[:tasks_summary][:running] %>&nbsp;running,
80                 <%= current_job[:tasks_summary][:todo] %>&nbsp;pending
81               </span>
82             </div>
83           <% elsif current_job[:state].in? ["Complete", "Failed", "Cancelled"] %>
84             <%# column offset 8 %>
85             <div class="col-md-4 text-overflow-ellipsis">
86               <% if pj[:output_uuid] %>
87                 <%= link_to_arvados_object_if_readable(pj[:output_uuid], 'Output data not available', friendly_name: true) %>
88               <% elsif current_job[:output] %>
89                 <%= link_to_arvados_object_if_readable(current_job[:output], 'Output data not available', link_text: "Output of #{pj[:name]}") %>
90               <% else %>
91                 No output.
92               <% end %>
93             </div>
94           <% end %>
95
96           <% if current_job[:state].in? ["Queued", "Running"] and @object.editable? %>
97             <%# column offset 11 %>
98             <div class="col-md-1 pipeline-instance-spacing">
99               <%= form_tag "/jobs/#{current_job[:uuid]}/cancel", remote: true, style: "display:inline; padding-left: 1em" do |f| %>
100                 <%= hidden_field_tag :return_to, url_for(@object) %>
101                 <%= button_tag "Cancel", {class: 'btn btn-xs btn-danger', id: "cancel-job-button"} %>
102               <% end %>
103             </div>
104           <% end %>
105         <% end %>
106       </div>
107     </div>
108   </div>
109
110   <div id="collapse<%= i %>" class="panel-collapse collapse <%= if expanded then 'in' end %>">
111     <div class="panel-body">
112       <div class="container">
113         <% current_component = (if current_job then current_job else pj end) %>
114         <div class="row">
115           <div class="col-md-6">
116             <table>
117               <% # link to repo tree/file only if the repo is readable
118                  # and the commit is a sha1...
119                  repo =
120                  (/^[0-9a-f]{40}$/ =~ current_component[:script_version] and
121                  Repository.where(name: current_component[:repository]).first)
122
123                  # ...and the api server provides an http:// or https:// url
124                  repo = nil unless repo.andand.http_fetch_url
125                  %>
126               <% [:script, :repository, :script_version, :supplied_script_version, :nondeterministic].each do |k| %>
127                 <tr>
128                   <td style="padding-right: 1em">
129                     <%= k.to_s %>:
130                   </td>
131                   <td>
132                     <% if current_component[k].nil? %>
133                       (none)
134                     <% elsif repo and k == :repository %>
135                       <%= link_to current_component[k], show_repository_tree_path(id: repo.uuid, commit: current_component[:script_version], path: '/') %>
136                     <% elsif repo and k == :script %>
137                       <%= link_to current_component[k], show_repository_blob_path(id: repo.uuid, commit: current_component[:script_version], path: 'crunch_scripts/'+current_component[:script]) %>
138                     <% elsif repo and k == :script_version %>
139                       <%= link_to current_component[k], show_repository_commit_path(id: repo.uuid, commit: current_component[:script_version]) %>
140                     <% else %>
141                       <%= current_component[k] %>
142                     <% end %>
143                   </td>
144                 </tr>
145               <% end %>
146               <% if current_component[:runtime_constraints].andand[:docker_image] and current_component[:docker_image_locator] %>
147                 <tr>
148                   <td style="padding-right: 1em">
149                     docker_image:
150                   </td>
151                   <td>
152                     <%= current_component[:runtime_constraints][:docker_image] %>
153                   </td>
154                 </tr>
155                 <tr>
156                   <td style="padding-right: 1em">
157                     docker_image_locator:
158                   </td>
159                   <td>
160                     <%= link_to_arvados_object_if_readable(current_component[:docker_image_locator],
161                       current_component[:docker_image_locator], friendly_name: true) %>
162                   </td>
163                 </tr>
164               <% else %>
165                 <tr>
166                   <td style="padding-right: 1em">
167                     docker_image:
168                   </td>
169                   <td>
170                     Not run in Docker
171                   </td>
172                 </tr>
173               <% end %>
174             </table>
175           </div>
176           <div class="col-md-5">
177             <table>
178               <% [:uuid, :modified_by_user_uuid, :priority, :created_at, :started_at, :finished_at].each do |k| %>
179                 <tr>
180                   <td style="padding-right: 1em">
181                     <%= k.to_s %>:
182                   </td>
183                   <td>
184                     <% if k == :uuid %>
185                       <%= link_to_arvados_object_if_readable(current_component[k], current_component[k], link_text: current_component[k]) %>
186                     <% elsif k.to_s.end_with? 'uuid' %>
187                       <%= link_to_arvados_object_if_readable(current_component[k], current_component[k], friendly_name: true) %>
188                     <% elsif k.to_s.end_with? '_at' %>
189                       <%= render_localized_date(current_component[k]) %>
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         </div>
205       </div>
206     </div>
207   </div>
208 </div>