lib/taskjuggler/daemon/ReportServer.rb in taskjuggler-3.1.0 vs lib/taskjuggler/daemon/ReportServer.rb in taskjuggler-3.2.0
- old
+ new
@@ -41,11 +41,11 @@
# communication from the parent to the child is not affected by the
# zombie DRb server in the child process.
rd, wr = IO.pipe
if (@pid = fork) == -1
- @log.fatal('ReportServer fork failed')
+ fatal('rs_fork_failed', 'ReportServer fork failed')
elsif @pid.nil?
if logConsole
# If the Broker wasn't daemonized, log stdout and stderr to PID
# specific files.
$stderr.reopen("tj3d.rs.#{$$}.stderr", 'w')
@@ -54,17 +54,17 @@
begin
# This is the child
$SAFE = 1
DRb.install_acl(ACL.new(%w[ deny all
allow 127.0.0.1 ]))
- DRb.start_service
iFace = ReportServerIface.new(self)
begin
uri = DRb.start_service('druby://127.0.0.1:0', iFace).uri
- @log.debug("Report server is listening on #{uri}")
+ debug('', "Report server is listening on #{uri}")
rescue
- @log.fatal("ReportServer can't start DRb: #{$!}")
+ error('rs_cannot_start_drb',
+ "ReportServer can't start DRb: #{$!}")
end
# Send the URI of the newly started DRb server to the parent process.
rd.close
wr.write uri
@@ -75,16 +75,20 @@
startTerminator
startWatchDog
# Cleanup the DRb threads
DRb.thread.join
- @log.debug('Report server terminated')
+ debug('', 'Report server terminated')
exit 0
- rescue
- $stderr.print $!.to_s
- $stderr.print $!.backtrace.join("\n")
- @log.fatal("ReportServer caught unexpected exception: #{$!}")
+ rescue => exception
+ # TjRuntimeError exceptions are simply passed through.
+ if exception.is_a?(TjRuntimeError)
+ raise TjRuntimeError, $!
+ end
+
+ error('rs_unexp_excp',
+ "ReportServer caught unexpected exception: #{$!}")
end
else
Process.detach(@pid)
# This is the parent
wr.close
@@ -98,63 +102,82 @@
end
def addFile(file)
begin
@tj.parseFile(file, :reportPropertiesFile)
- rescue TjException
+ rescue TjRuntimeError
return false
end
restartTimer
true
end
def generateReport(id, regExpMode, formats, dynamicAttributes)
- @log.info("Generating report #{id}")
+ info('generating_report', "Generating report #{id}")
startTime = Time.now
- if (ok = @tj.generateReport(id, regExpMode, formats, dynamicAttributes))
- @log.info("Report #{id} generated in #{Time.now - startTime} seconds")
- else
- @log.error("Report generation of #{id} failed")
+ begin
+ if (ok = @tj.generateReport(id, regExpMode, formats, dynamicAttributes))
+ info('report_id_generated',
+ "Report #{id} generated in #{Time.now - startTime} seconds")
+ else
+ error('report_generation_failed', "Report generation of #{id} failed")
+ end
+ rescue TjRuntimeError
+ return false
end
restartTimer
ok
end
def listReports(id, regExpMode)
- @log.info("Listing report #{id}")
- if (ok = @tj.listReports(id, regExpMode))
- @log.debug("Report list for #{id} generated")
- else
- @log.error("Report list compilation of #{id} failed")
+ info('listing_report_id', "Listing report #{id}")
+ begin
+ if (ok = @tj.listReports(id, regExpMode))
+ debug('', "Report list for #{id} generated")
+ else
+ error('repor_list_comp_failed',
+ "Report list compilation of #{id} failed")
+ end
+ rescue TjRuntimeError
+ return false
end
restartTimer
ok
end
def checkTimeSheet(sheet)
- @log.info("Checking time sheet #{sheet}")
- ok = @tj.checkTimeSheet(sheet)
- @log.debug("Time sheet #{sheet} is #{ok ? '' : 'not '}ok")
+ info('check_time_sheet', "Checking time sheet #{sheet}")
+ begin
+ ok = @tj.checkTimeSheet(sheet)
+ debug('', "Time sheet #{sheet} is #{ok ? '' : 'not '}ok")
+ rescue TjRuntimeError
+ return false
+ end
restartTimer
ok
end
def checkStatusSheet(sheet)
- @log.info("Checking status sheet #{sheet}")
- ok = @tj.checkStatusSheet(sheet)
- @log.debug("Status sheet #{sheet} is #{ok ? '' : 'not '}ok")
+ info('check_status_sheet', "Checking status sheet #{sheet}")
+ begin
+ ok = @tj.checkStatusSheet(sheet)
+ debug('', "Status sheet #{sheet} is #{ok ? '' : 'not '}ok")
+ rescue TjRuntimeError
+ return false
+ end
restartTimer
ok
end
private
def startWatchDog
Thread.new do
loop do
if TjTime.new - @lastPing > 120
- @log.fatal('Heartbeat from ProjectServer lost. Terminating.')
+ error('ps_heartbeat_lost',
+ 'Heartbeat from ProjectServer lost. Terminating.')
end
sleep 30
end
end
end
@@ -179,10 +202,11 @@
return false unless @server.checkKey(authKey, 'addFile')
trap { @server.addFile(file) }
end
- def generateReport(authKey, reportId, regExpMode, formats, dynamicAttributes)
+ def generateReport(authKey, reportId, regExpMode, formats,
+ dynamicAttributes)
return false unless @server.checkKey(authKey, 'generateReport')
trap do
@server.generateReport(reportId, regExpMode, formats, dynamicAttributes)
end