From 032410391466b9bc1fbd6e7bb05a4c7632400200 Mon Sep 17 00:00:00 2001 From: yma Date: Tue, 17 Dec 2024 19:06:31 +0800 Subject: [PATCH] Change generation executor to CompletableFuture async --- .../archive/controller/ArchiveController.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java b/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java index 9eb1ccc..5736cbd 100644 --- a/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java +++ b/src/main/java/org/commonjava/indy/service/archive/controller/ArchiveController.java @@ -59,14 +59,13 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -171,7 +170,7 @@ public void generate( HistoricalContentDTO content ) } recordInProgress( buildConfigId ); - Future future = generateExecutor.submit( () -> { + CompletableFuture future = CompletableFuture.runAsync( () -> { try { doGenerate( content ); @@ -189,27 +188,16 @@ public void generate( HistoricalContentDTO content ) buildConfigLocks.remove( buildConfigId ); logger.info( "<< { + // If timeout happens on generation, cancel and remove the status to make sure following generation + removeStatus( buildConfigId ); + cleanupBCWorkspace( buildConfigId ); + logger.error( "Generation timeout for buildConfigId {}", buildConfigId ); + return null; + } ); } }