class TaskJuggler::ReportServer

Attributes

authKey[R]
uri[R]

Public Class Methods

new(tj, logConsole = false) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 25
def initialize(tj, logConsole = false)
  initIntercom

  @pid = nil
  @uri = nil

  # A reference to the TaskJuggler object that holds the project data.
  @tj = tj
  # This is set to the ID(s) of the reports that should be generated.
  @reportId = 'unknown'

  @lastPing = TjTime.new

  # We've started a DRb server before. This will continue to live somewhat
  # in the child. All attempts to create a DRb connection from the child
  # to the parent will end up in the child again. So we use a Pipe to
  # communicate the URI of the child DRb server to the parent. The
  # 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
    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')
      $stdout.reopen("tj3d.rs.#{$$}.stdout", 'w')
    end
    begin
      # This is the child
      $SAFE = 1
      DRb.install_acl(ACL.new(%w[ deny all
                                  allow 127.0.0.1 ]))
      iFace = ReportServerIface.new(self)
      begin
        uri = DRb.start_service('druby://127.0.0.1:0', iFace).uri
        debug('', "Report server is listening on #{uri}")
      rescue
        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
      wr.close

      # Start a Thread that waits for the @terminate flag to be set and does
      # other background tasks.
      startTerminator
      startWatchDog

      # Cleanup the DRb threads
      DRb.thread.join
      debug('', 'Report server terminated')
      exit 0
    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
    @uri = rd.read
    rd.close
  end
end

Public Instance Methods

addFile(file) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 105
def addFile(file)
  begin
    @tj.parseFile(file, :reportPropertiesFile)
  rescue TjRuntimeError
    return false
  end
  restartTimer
  true
end
checkStatusSheet(sheet) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 162
def checkStatusSheet(sheet)
  info('check_status_sheet', "Checking status sheet #{sheet}")
  @reportId = 'statussheet'
  begin
    ok = @tj.checkStatusSheet(sheet)
    debug('', "Status sheet #{sheet} is #{ok ? '' : 'not '}ok")
  rescue TjRuntimeError
    return false
  end
  restartTimer
  ok
end
checkTimeSheet(sheet) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 149
def checkTimeSheet(sheet)
  info('check_time_sheet', "Checking time sheet #{sheet}")
  @reportId = 'timesheet'
  begin
    ok = @tj.checkTimeSheet(sheet)
    debug('', "Time sheet #{sheet} is #{ok ? '' : 'not '}ok")
  rescue TjRuntimeError
    return false
  end
  restartTimer
  ok
end
generateReport(id, regExpMode, formats, dynamicAttributes) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 115
def generateReport(id, regExpMode, formats, dynamicAttributes)
  info('generating_report', "Generating report #{id}")
  startTime = Time.now
  @reportId = id
  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
listReports(id, regExpMode) click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 133
def listReports(id, regExpMode)
  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
ping() click to toggle source
# File lib/taskjuggler/daemon/ReportServer.rb, line 101
def ping
  @lastPing = TjTime.new
end