Skip to content

Commit

Permalink
Merge pull request #55 from yma96/1.1.x
Browse files Browse the repository at this point in the history
Change generation executor to CompletableFuture async
  • Loading branch information
yma96 authored Dec 18, 2024
2 parents 72e75d3 + 0324103 commit ea3ee5e
Showing 1 changed file with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,7 +170,7 @@ public void generate( HistoricalContentDTO content )
}

recordInProgress( buildConfigId );
Future<?> future = generateExecutor.submit( () -> {
CompletableFuture<Void> future = CompletableFuture.runAsync( () -> {
try
{
doGenerate( content );
Expand All @@ -189,27 +188,16 @@ public void generate( HistoricalContentDTO content )
buildConfigLocks.remove( buildConfigId );
logger.info( "<<<Lock released for buildConfigId {}", buildConfigId );
}
} );
try
{
future.get( preSeedConfig.generationTimeoutMinutes().orElse( 60 ), TimeUnit.MINUTES );
}
catch ( TimeoutException e )
{
// If timeout happens on generation, cancel and remove the status to make sure following generation
future.cancel( true );
removeStatus( buildConfigId );
cleanupBCWorkspace( buildConfigId );
logger.error( "Generation timeout for buildConfigId {}", buildConfigId, e );
}
catch ( InterruptedException | ExecutionException e )
{
// If future task level error happens on generation, cancel and remove the status to make sure following generation
future.cancel( true );
removeStatus( buildConfigId );
cleanupBCWorkspace( buildConfigId );
logger.error( "Generation future task level failed for buildConfigId {}", buildConfigId, e );
}
}, generateExecutor );

future.orTimeout( preSeedConfig.generationTimeoutMinutes().orElse( 60 ), TimeUnit.MINUTES )
.exceptionally( ex -> {
// 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;
} );
}
}

Expand Down

0 comments on commit ea3ee5e

Please sign in to comment.