joblog.detail.1.js 2.8 KB

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