diff --git a/gate-core/src/main/java/com/netflix/spinnaker/gate/services/TaskService.java b/gate-core/src/main/java/com/netflix/spinnaker/gate/services/TaskService.java index 8b09b5bd8f..955bce5217 100644 --- a/gate-core/src/main/java/com/netflix/spinnaker/gate/services/TaskService.java +++ b/gate-core/src/main/java/com/netflix/spinnaker/gate/services/TaskService.java @@ -21,6 +21,9 @@ import com.netflix.spinnaker.gate.services.internal.OrcaServiceSelector; import com.netflix.spinnaker.security.AuthenticatedRequest; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; import lombok.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +40,8 @@ public class TaskService { private ClouddriverServiceSelector clouddriverServiceSelector; private TaskServiceProperties taskServiceProperties; + @Autowired ExecutorService executorService; + @Autowired public TaskService( OrcaServiceSelector orcaServiceSelector, @@ -132,10 +137,25 @@ public Map createAndWaitForCompletion(Map body, int maxPolls) { } public Map createAndWaitForCompletion(Map body) { - return createAndWaitForCompletion( - body, - taskServiceProperties.getMaxNumberOfPolls(), - taskServiceProperties.getDefaultIntervalBetweenPolls()); + CompletableFuture future = + CompletableFuture.supplyAsync( + () -> { + return createAndWaitForCompletion( + body, + taskServiceProperties.getMaxNumberOfPolls(), + taskServiceProperties.getDefaultIntervalBetweenPolls()); + }, + executorService) + .thenApply( + result -> { + return result; + }); + + try { + return future.get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } } /** @deprecated This pipeline operation does not belong here. */