Skip to content

Commit

Permalink
Fix: hb_report: indicate the 'crm report' failure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aleksei Burlakov committed Sep 23, 2024
1 parent 8945dc8 commit 335c10c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion hawk/app/assets/javascripts/module/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ $(function() {
clearInterval(running_timeout);
running_timeout = null;
}
$.growl({ message: __("Report generation is complete.") }, { type: 'success' });
if (state.report_generated) {
$.growl({ message: __("Report generation is complete.") }, { type: 'success' });
} else {
$.growl({ message: __("Failed to create the report: " + state.msg ) }, { type: 'danger' });
}
$('#reports #middle table.reports').bootstrapTable('refresh');
build_tabs();
}
Expand Down
3 changes: 2 additions & 1 deletion hawk/app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def running
@hb_report = HbReport.new
running = @hb_report.running?
t = running ? @hb_report.lasttime : nil
render json: { running: running, time: (t || ["", ""]) }
rc = @hb_report.report_generated?
render json: { running: running, time: (t || ["", ""]), report_generated: rc[:code], msg: rc[:msg] }
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions hawk/app/lib/hb_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def running?
Util.child_active(@pidfile)
end

def report_generated?
return { code: false, msg: '' } if !File.exist?(@exitfile) || !File.exist?(@timefile)

rc = File.read(@exitfile).to_i
return { code: true, msg: '' } if rc==0

lt = lasttime
errfile = Rails.root.join('tmp', 'reports', "hawk-#{lt[0]}-#{lt[1]}.stderr").to_s
return { code: false, msg: '' }if !File.exist?(errfile)

err_msg = File.new(errfile).read.split("\n")[0]
return { code: false, msg: err_msg }
end

def cancel!
pid = File.new(@pidfile).read.to_i
return 0 if pid <= 0
Expand Down

0 comments on commit 335c10c

Please sign in to comment.