-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompleted.html.erb
More file actions
139 lines (116 loc) · 4.39 KB
/
Copy pathcompleted.html.erb
File metadata and controls
139 lines (116 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<% if !connect.user.blank? %>
<%
def file_url(base, path)
encoded_path = path.to_s.split("/").reject(&:empty?).map { |segment| ERB::Util.url_encode(segment) }.join("/")
"#{base}/#{encoded_path}"
end
def tail_text(path, max_bytes = 8192, max_lines = 10)
return nil unless File.file?(path)
File.open(path, "rb") do |file|
size = file.size
offset = [size - max_bytes, 0].max
file.seek(offset)
text = file.read.to_s
if offset > 0
newline_index = text.index("\n")
text = newline_index ? text[(newline_index + 1)..] : text
end
lines = text.lines
lines = lines.last(max_lines) if max_lines && max_lines > 0
lines.join
end
end
def sanitize_live_log(text)
return nil if text.nil?
ansi_pattern = /\e\[[0-9;?]*[ -\/]*[@-~]/
lines = text.gsub(ansi_pattern, "").split("\n")
cleaned = []
index = 0
while index < lines.length
line = lines[index]
if line.start_with?("WARN: cpus and memory directives are ignored when clusterOptions contains -l option")
index += 1
index += 1 while index < lines.length && lines[index].start_with?("tip:", "- ")
next
end
if line.start_with?("WARN: [PBSPRO] queue status cannot be fetched")
index += 1
index += 1 while index < lines.length && !lines[index].strip.empty?
index += 1 if index < lines.length && lines[index].strip.empty?
next
end
cleaned << line
index += 1
end
compact = []
blank_streak = 0
cleaned.each do |line|
if line.strip.empty?
blank_streak += 1
compact << "" if blank_streak == 1
else
blank_streak = 0
compact << line
end
end
compact.join("\n").strip
end
def sanitize_output_log(text)
return nil if text.nil?
lines = text.split("\n")
cleaned = []
index = 0
while index < lines.length
line = lines[index]
if line.start_with?("WARN: [PBSPRO] queue status cannot be fetched")
index += 1
index += 1 while index < lines.length && !lines[index].strip.empty?
index += 1 if index < lines.length && lines[index].strip.empty?
next
end
if line.strip == "Cleaning up..."
break
end
if line.match?(/^=+$/) && index + 1 < lines.length && lines[index + 1].include?("Resource Usage on ")
break
end
cleaned << line
index += 1
end
while cleaned.any? && cleaned.last.strip.empty?
cleaned.pop
end
cleaned.join("\n").strip
end
base_out_dir = (connect.respond_to?(:base_out_dir) && !connect.base_out_dir.blank?) ? connect.base_out_dir : portal_default_base_out_dir
results_url_base = (connect.respond_to?(:results_url_base) && !connect.results_url_base.blank?) ? connect.results_url_base : portal_default_results_url_base
session_output_dir = (connect.respond_to?(:session_output_dir) && !connect.session_output_dir.blank?) ? connect.session_output_dir : nil
log_dir = session_output_dir || File.join(base_out_dir, connect.run_dir)
live_log_path = File.join(log_dir, "live_log.log")
live_log_url = file_url(results_url_base, live_log_path)
output_log_path = File.join(log_dir, "output.log")
output_log_url = file_url(results_url_base, output_log_path)
summary_log_url = File.file?(output_log_path) ? output_log_url : live_log_url
summary_log_label = File.file?(output_log_path) ? "output.log" : "live_log.log"
log_text = if File.file?(output_log_path)
sanitize_output_log(tail_text(output_log_path, 16384, 40))
else
sanitize_live_log(tail_text(live_log_path))
end
%>
<div class="ood-completed-log-card">
<div><b>Log</b>: <a target="_blank" rel="noopener" href="https://kod.restech.unsw.edu.au<%= summary_log_url %>"><%= summary_log_label %></a></div>
<% if log_text && !log_text.empty? %>
<pre class="ood-completed-log" style="margin-top: 0.75rem !important; height: 7rem !important; max-height: 7rem !important; overflow: auto !important; padding: 1rem !important; background: #0f172a !important; color: #f8fafc !important; border: 1px solid #334155 !important; border-radius: 0.5rem !important; white-space: pre-wrap !important; font: 0.9rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace !important;"><%= ERB::Util.html_escape(log_text) %></pre>
<script>
(() => {
const scriptEl = document.currentScript;
const logEl = scriptEl ? scriptEl.previousElementSibling : null;
window.requestAnimationFrame(() => {
if (logEl) logEl.scrollTop = logEl.scrollHeight;
});
})();
</script>
<% end %>
</div>
<% end %>