Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ private static class Watcher implements Runnable {
private final Handler handler;
private final TaskListener listener;
private final @CheckForNull Charset cs;
private long lastLocation = -1;

Watcher(FileMonitoringController controller, FilePath workspace, Handler handler, TaskListener listener) {
LOGGER.log(Level.FINE, "starting " + this, new Throwable());
Expand All @@ -616,10 +617,17 @@ private static class Watcher implements Runnable {
@Override public void run() {
try {
Integer exitStatus = controller.exitStatus(workspace, listener); // check before collecting output, in case the process is just now finishing
long lastLocation = 0;
FilePath lastLocationFile = controller.getLastLocationFile(workspace);
if (lastLocationFile.exists()) {
lastLocation = Long.parseLong(lastLocationFile.readToString());
if (lastLocation == -1) {
FilePath lastLocationFile = controller.getLastLocationFile(workspace);
if (lastLocationFile.exists()) {
lastLocation = Long.parseLong(lastLocationFile.readToString());
LOGGER.finest(() -> "Loaded lastLocation=" + lastLocation);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to actually be missing from test coverage in this plugin currently; workflow-durable-task-step does exercise it in tests relating to agent disconnections and controller restarts.

} else {
lastLocation = 0;
LOGGER.finest("New watch, lastLocation=0");
}
} else {
LOGGER.finest(() -> "Using cached lastLocation=" + lastLocation);
}
FilePath logFile = controller.getLogFile(workspace);
long len = logFile.length();
Expand All @@ -630,9 +638,11 @@ private static class Watcher implements Runnable {
InputStream utf8EncodedStream = cs == null ? locallyEncodedStream : new ReaderInputStream(new InputStreamReader(locallyEncodedStream, cs), StandardCharsets.UTF_8);
handler.output(utf8EncodedStream);
long newLocation = ch.position();
lastLocationFile.write(Long.toString(newLocation), null);
// TODO use AtomicFileWriter or equivalent?
controller.getLastLocationFile(workspace).write(Long.toString(newLocation), null);
long delta = newLocation - lastLocation;
LOGGER.finer(() -> this + " copied " + delta + " bytes from " + logFile);
lastLocation = newLocation;
}
}
if (exitStatus != null) {
Expand Down