Let background computations abort for browse command

This commit is contained in:
Rene Pfeuffer
2019-12-12 11:47:03 +01:00
parent f7dc89ee81
commit 8df43e7b4e
12 changed files with 122 additions and 29 deletions

View File

@@ -28,6 +28,7 @@ public class FileObjectDto extends HalRepresentation {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String revision;
private boolean partialResult;
private boolean computationAborted;
public FileObjectDto(Links links, Embedded embedded) {
super(links, embedded);

View File

@@ -4,6 +4,7 @@ import sonia.scm.repository.spi.SyncAsyncExecutor;
import java.time.Instant;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import static sonia.scm.repository.spi.SyncAsyncExecutor.ExecutionType.ASYNCHRONOUS;
@@ -11,18 +12,35 @@ import static sonia.scm.repository.spi.SyncAsyncExecutor.ExecutionType.SYNCHRONO
public class DefaultSyncAsyncExecutor implements SyncAsyncExecutor {
public static final long DEFAULT_MAX_ASYNC_RUNTIME = 60 * 1000L;
private final Executor executor;
private final Instant switchToAsyncTime;
private final long maxAsyncRuntime;
private AtomicLong asyncRuntime = new AtomicLong(0L);
private boolean executedAllSynchronously = true;
DefaultSyncAsyncExecutor(Executor executor, Instant switchToAsyncTime) {
this.executor = executor;
this.switchToAsyncTime = switchToAsyncTime;
this(executor, switchToAsyncTime, DEFAULT_MAX_ASYNC_RUNTIME);
}
public ExecutionType execute(Consumer<ExecutionType> runnable) {
DefaultSyncAsyncExecutor(Executor executor, Instant switchToAsyncTime, long maxAsyncRuntime) {
this.executor = executor;
this.switchToAsyncTime = switchToAsyncTime;
this.maxAsyncRuntime = maxAsyncRuntime;
}
public ExecutionType execute(Consumer<ExecutionType> runnable, Runnable abortionFallback) {
if (Instant.now().isAfter(switchToAsyncTime)) {
executor.execute(() -> runnable.accept(ASYNCHRONOUS));
executor.execute(() -> {
if (asyncRuntime.get() < maxAsyncRuntime) {
long chunkStartTime = System.currentTimeMillis();
runnable.accept(ASYNCHRONOUS);
asyncRuntime.addAndGet(System.currentTimeMillis() - chunkStartTime);
} else {
abortionFallback.run();
}
});
executedAllSynchronously = false;
return ASYNCHRONOUS;
} else {