mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
Let background computations abort for browse command
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user