diff --git a/hawk/app/assets/javascripts/module/reports.js b/hawk/app/assets/javascripts/module/reports.js index 66b4e6e7..c1433f72 100644 --- a/hawk/app/assets/javascripts/module/reports.js +++ b/hawk/app/assets/javascripts/module/reports.js @@ -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(); } diff --git a/hawk/app/controllers/reports_controller.rb b/hawk/app/controllers/reports_controller.rb index 2f4aca69..66fa8339 100644 --- a/hawk/app/controllers/reports_controller.rb +++ b/hawk/app/controllers/reports_controller.rb @@ -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 diff --git a/hawk/app/lib/hb_report.rb b/hawk/app/lib/hb_report.rb index ed2258c2..af305384 100644 --- a/hawk/app/lib/hb_report.rb +++ b/hawk/app/lib/hb_report.rb @@ -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