Commit f12a9074 authored by Jens Korinth's avatar Jens Korinth
Browse files

Fix truncated log output in verbose mode

* when an activity exits quickly with an error, verbose mode would often
  omit the most important last few lines of the log
* reason: flushing the data to disk takes longer than for the Tapasco
  threads to die, thus LogTrackingFileWatcher exits before lines appear
* workaround: when both waitingFor and files are empty, MultiFileWatcher
  now waits one more iteration before exiting, which seems to suffice
parent f9148c81
Pipeline #188 canceled with stages
in 30 minutes and 49 seconds
......@@ -100,14 +100,17 @@ class MultiFileWatcher(pollInterval: Int = MultiFileWatcher.POLL_INTERVAL) exten
if (_watchThread.compareAndSet(None, Some(new Thread(new Runnable {
def run() {
try {
while (! _files.isEmpty || ! _waitingFor.isEmpty) {
Thread.sleep(pollInterval)
var lastWasEmpty = false
while (! _files.isEmpty || ! _waitingFor.isEmpty || ! lastWasEmpty) {
val waits = _waitingFor.synchronized { _waitingFor.toList }
val files = _files.synchronized { _files.toMap }
Thread.sleep(pollInterval)
waits foreach { p =>
logger.trace("waiting for {}", p)
if (open(p)) _waitingFor.synchronized { _waitingFor -= p }
}
val files = _files.synchronized { _files.toMap }
val all_files = files ++ _files.synchronized { _files.toMap }
logger.trace("reading from files: {}", files)
files foreach { case (p, br) =>
val lines = readFrom(br)
if (lines.length > 0) {
......@@ -115,12 +118,14 @@ class MultiFileWatcher(pollInterval: Int = MultiFileWatcher.POLL_INTERVAL) exten
publish(LinesAdded(p, lines))
}
}
lastWasEmpty = files.isEmpty
}
_watchThread.set(None)
} catch { case e: InterruptedException => _watchThread.set(None) }
}
})))) {
_watchThread.get map (_.start)
Thread.sleep(100)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment