21
21
import com .netflix .spinnaker .gate .services .internal .OrcaServiceSelector ;
22
22
import com .netflix .spinnaker .security .AuthenticatedRequest ;
23
23
import java .util .*;
24
+ import java .util .concurrent .CompletableFuture ;
25
+ import java .util .concurrent .ExecutionException ;
26
+ import java .util .concurrent .ExecutorService ;
24
27
import lombok .Data ;
25
28
import org .slf4j .Logger ;
26
29
import org .slf4j .LoggerFactory ;
@@ -37,6 +40,8 @@ public class TaskService {
37
40
private ClouddriverServiceSelector clouddriverServiceSelector ;
38
41
private TaskServiceProperties taskServiceProperties ;
39
42
43
+ @ Autowired ExecutorService executorService ;
44
+
40
45
@ Autowired
41
46
public TaskService (
42
47
OrcaServiceSelector orcaServiceSelector ,
@@ -132,10 +137,25 @@ public Map createAndWaitForCompletion(Map body, int maxPolls) {
132
137
}
133
138
134
139
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
+ }
139
159
}
140
160
141
161
/** @deprecated This pipeline operation does not belong here. */
0 commit comments