Skip to content

Commit

Permalink
Merge pull request #234 from jglick/TimeoutStepExecution
Browse files Browse the repository at this point in the history
Better fix of `timeout` activity tick after restart
  • Loading branch information
jglick authored Aug 30, 2022
2 parents 43d80fe + 512d920 commit d57e3ca
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private void setupTimer(final long now, boolean forceReset) {
}

private void resetTimer() {
LOGGER.fine(() -> "resetting timer on " + id);
long now = System.currentTimeMillis();
end = now + timeout;
setupTimer(now, true);
Expand Down Expand Up @@ -340,9 +341,6 @@ public OutputStream decorateLogger(@SuppressWarnings("rawtypes") Run build, fina
OutputStream decorated = new LineTransformationOutputStream() {
@Override
protected void eol(byte[] b, int len) throws IOException {
if (channel == null) {
new ResetTimer(id).call();
}
logger.write(b, 0, len);
active.set(true);
}
Expand All @@ -359,9 +357,7 @@ public void close() throws IOException {
logger.close();
}
};
if (channel != null) {
new Tick(active, new WeakReference<>(decorated), timeout, channel, id).schedule();
}
new Tick(active, new WeakReference<>(decorated), timeout, channel, id).schedule(0);
return decorated;
}
}
Expand Down Expand Up @@ -397,16 +393,14 @@ public void run() {
} else {
resetTimer.call();
}
schedule();
schedule(timeout / 2); // less than the full timeout, to give some grace period, but in the same ballpark to avoid overhead
} else {
// Idle at the moment, but check well before the timeout expires in case new output appears.
schedule(timeout / 10);
}
}
void schedule() {
schedule(timeout / 2); // less than the full timeout, to give some grace period, but in the same ballpark to avoid overhead
}
private void schedule(long delay) {
LOGGER.fine(() -> "scheduling tick for " + Util.getTimeSpanString(delay));
Timer.get().schedule(this, delay, TimeUnit.MILLISECONDS);
}
}
Expand Down

0 comments on commit d57e3ca

Please sign in to comment.