提交 | 用户 | 时间
|
e7c126
|
1 |
$(function() { |
H |
2 |
|
|
3 |
// trigger fail, end |
|
4 |
if ( !(triggerCode == 200 || handleCode != 0) ) { |
|
5 |
$('#logConsoleRunning').hide(); |
|
6 |
$('#logConsole').append('<span style="color: red;">'+ I18n.joblog_rolling_log_triggerfail +'</span>'); |
|
7 |
return; |
|
8 |
} |
|
9 |
|
|
10 |
// pull log |
|
11 |
var fromLineNum = 1; // [from, to], start as 1 |
|
12 |
var pullFailCount = 0; |
|
13 |
function pullLog() { |
|
14 |
// pullFailCount, max=20 |
|
15 |
if (pullFailCount++ > 20) { |
|
16 |
logRunStop('<span style="color: red;">'+ I18n.joblog_rolling_log_failoften +'</span>'); |
|
17 |
return; |
|
18 |
} |
|
19 |
|
|
20 |
// load |
|
21 |
console.log("pullLog, fromLineNum:" + fromLineNum); |
|
22 |
|
|
23 |
$.ajax({ |
|
24 |
type : 'POST', |
|
25 |
async: false, // sync, make log ordered |
|
26 |
url : base_url + '/joblog/logDetailCat', |
|
27 |
data : { |
|
28 |
"logId":logId, |
|
29 |
"fromLineNum":fromLineNum |
|
30 |
}, |
|
31 |
dataType : "json", |
|
32 |
success : function(data){ |
|
33 |
|
|
34 |
if (data.code == 200) { |
|
35 |
if (!data.content) { |
|
36 |
console.log('pullLog fail'); |
|
37 |
return; |
|
38 |
} |
|
39 |
if (fromLineNum != data.content.fromLineNum) { |
|
40 |
console.log('pullLog fromLineNum not match'); |
|
41 |
return; |
|
42 |
} |
|
43 |
if (fromLineNum > data.content.toLineNum ) { |
|
44 |
console.log('pullLog already line-end'); |
|
45 |
|
|
46 |
// valid end |
|
47 |
if (data.content.end) { |
|
48 |
logRunStop('<br><span style="color: green;">[Rolling Log Finish]</span>'); |
|
49 |
return; |
|
50 |
} |
|
51 |
|
|
52 |
return; |
|
53 |
} |
|
54 |
|
|
55 |
// append content |
|
56 |
fromLineNum = data.content.toLineNum + 1; |
|
57 |
$('#logConsole').append(data.content.logContent); |
|
58 |
pullFailCount = 0; |
|
59 |
|
|
60 |
// scroll to bottom |
|
61 |
scrollTo(0, document.body.scrollHeight); // $('#logConsolePre').scrollTop( document.body.scrollHeight + 300 ); |
|
62 |
|
|
63 |
} else { |
|
64 |
console.log('pullLog fail:'+data.msg); |
|
65 |
} |
|
66 |
} |
|
67 |
}); |
|
68 |
} |
|
69 |
|
|
70 |
// pull first page |
|
71 |
pullLog(); |
|
72 |
|
|
73 |
// handler already callback, end |
|
74 |
if (handleCode > 0) { |
|
75 |
logRunStop('<br><span style="color: green;">[Load Log Finish]</span>'); |
|
76 |
return; |
|
77 |
} |
|
78 |
|
|
79 |
// round until end |
|
80 |
var logRun = setInterval(function () { |
|
81 |
pullLog() |
|
82 |
}, 3000); |
|
83 |
function logRunStop(content){ |
|
84 |
$('#logConsoleRunning').hide(); |
|
85 |
logRun = window.clearInterval(logRun); |
|
86 |
$('#logConsole').append(content); |
|
87 |
} |
|
88 |
|
|
89 |
}); |