Skip to content

Commit 3c899ce

Browse files
author
Aleksei Burlakov
committed
Fix: hb_report: indicate the 'crm report' failure
Previously, even if the crm report had failed, the hawk would show the green status. In this change, we add reading ./tmp/pids/report.exit and ./tmp/reports/<report-file>.stderr We return the first line of the error message and the red status, if the execution has failed.
1 parent 8945dc8 commit 3c899ce

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

hawk/app/assets/javascripts/module/reports.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ $(function() {
2828
clearInterval(running_timeout);
2929
running_timeout = null;
3030
}
31-
$.growl({ message: __("Report generation is complete.") }, { type: 'success' });
31+
if (state.report_generated) {
32+
$.growl({ message: __("Report generation is complete.") }, { type: 'success' });
33+
} else {
34+
$.growl({ message: __("Failed to create the report: " + state.msg ) }, { type: 'danger' });
35+
}
3236
$('#reports #middle table.reports').bootstrapTable('refresh');
3337
build_tabs();
3438
}

hawk/app/controllers/reports_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def running
109109
@hb_report = HbReport.new
110110
running = @hb_report.running?
111111
t = running ? @hb_report.lasttime : nil
112-
render json: { running: running, time: (t || ["", ""]) }
112+
rc = @hb_report.report_generated?
113+
render json: { running: running, time: (t || ["", ""]), report_generated: rc[:code], msg: rc[:msg] }
113114
end
114115
end
115116
end

hawk/app/lib/hb_report.rb

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ def running?
3838
Util.child_active(@pidfile)
3939
end
4040

41+
def report_generated?
42+
return { code: false, msg: '' } if !File.exist?(@exitfile) || !File.exist?(@timefile)
43+
44+
rc = File.read(@exitfile).to_i
45+
return { code: true, msg: '' } if rc==0
46+
47+
lt = lasttime
48+
errfile = Rails.root.join('tmp', 'reports', "hawk-#{lt[0]}-#{lt[1]}.stderr").to_s
49+
return { code: false, msg: '' }if !File.exist?(errfile)
50+
51+
err_msg = File.new(errfile).read.split("\n")[0]
52+
return { code: false, msg: err_msg }
53+
end
54+
4155
def cancel!
4256
pid = File.new(@pidfile).read.to_i
4357
return 0 if pid <= 0
@@ -119,4 +133,5 @@ def generate(from_time, to_time, all_nodes = true)
119133
f.close
120134
Process.detach(pid)
121135
end
136+
122137
end

0 commit comments

Comments
 (0)