Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: hb_report: indicate the 'crm report' failure #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading