Skip to content

Commit 9daca0f

Browse files
refactor(taskService): Adding a scheduled executor to retrieve the task status
1 parent 487f0d3 commit 9daca0f

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

gate-core/src/main/java/com/netflix/spinnaker/gate/services/TaskService.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.netflix.spinnaker.gate.services.internal.OrcaServiceSelector;
2222
import com.netflix.spinnaker.security.AuthenticatedRequest;
2323
import java.util.*;
24+
import java.util.concurrent.CompletableFuture;
25+
import java.util.concurrent.ExecutionException;
26+
import java.util.concurrent.ExecutorService;
2427
import lombok.Data;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
@@ -37,6 +40,8 @@ public class TaskService {
3740
private ClouddriverServiceSelector clouddriverServiceSelector;
3841
private TaskServiceProperties taskServiceProperties;
3942

43+
@Autowired ExecutorService executorService;
44+
4045
@Autowired
4146
public TaskService(
4247
OrcaServiceSelector orcaServiceSelector,
@@ -132,10 +137,25 @@ public Map createAndWaitForCompletion(Map body, int maxPolls) {
132137
}
133138

134139
public Map createAndWaitForCompletion(Map body) {
135-
return createAndWaitForCompletion(
136-
body,
137-
taskServiceProperties.getMaxNumberOfPolls(),
138-
taskServiceProperties.getDefaultIntervalBetweenPolls());
140+
CompletableFuture<Map> future =
141+
CompletableFuture.supplyAsync(
142+
() -> {
143+
return createAndWaitForCompletion(
144+
body,
145+
taskServiceProperties.getMaxNumberOfPolls(),
146+
taskServiceProperties.getDefaultIntervalBetweenPolls());
147+
},
148+
executorService)
149+
.thenApply(
150+
result -> {
151+
return result;
152+
});
153+
154+
try {
155+
return future.get();
156+
} catch (InterruptedException | ExecutionException e) {
157+
throw new RuntimeException(e);
158+
}
139159
}
140160

141161
/** @deprecated This pipeline operation does not belong here. */

0 commit comments

Comments
 (0)