Skip to content

Commit

Permalink
Merge pull request #288 from aleksei-burlakov/dev-check-report-error
Browse files Browse the repository at this point in the history
Fix: hb_report: indicate the 'crm report' failure
  • Loading branch information
aleksei-burlakov authored Sep 26, 2024
2 parents 8945dc8 + 1bda8e9 commit 9f555fd
Show file tree
Hide file tree
Showing 3 changed files with 24 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
17 changes: 17 additions & 0 deletions hawk/app/lib/hb_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ 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
# .stderr file must exist even if there was no error
return { code: false, msg: '' } if !File.exist?(errfile)

err_text = File.read(errfile).split("\n")
err_msg = '<br>' + err_text[0]
err_msg += '<br>...<br>' + err_text[-1] if err_text.length() > 1
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 9f555fd

Please sign in to comment.