|
17 | 17 | package io.spring.concourse.releasescripts.bintray;
|
18 | 18 |
|
19 | 19 | import java.net.URI;
|
| 20 | +import java.util.Objects; |
| 21 | +import java.util.concurrent.TimeUnit; |
20 | 22 |
|
21 | 23 | import io.spring.concourse.releasescripts.ReleaseInfo;
|
22 | 24 | import io.spring.concourse.releasescripts.sonatype.SonatypeProperties;
|
23 | 25 | import io.spring.concourse.releasescripts.sonatype.SonatypeService;
|
24 | 26 | import io.spring.concourse.releasescripts.system.ConsoleLogger;
|
| 27 | +import org.awaitility.core.ConditionTimeoutException; |
25 | 28 |
|
26 | 29 | import org.springframework.boot.web.client.RestTemplateBuilder;
|
| 30 | +import org.springframework.http.HttpStatus; |
27 | 31 | import org.springframework.http.MediaType;
|
28 | 32 | import org.springframework.http.RequestEntity;
|
29 | 33 | import org.springframework.stereotype.Component;
|
30 | 34 | import org.springframework.web.client.HttpClientErrorException;
|
31 | 35 | import org.springframework.web.client.RestTemplate;
|
32 | 36 |
|
| 37 | +import static org.awaitility.Awaitility.waitAtMost; |
| 38 | + |
33 | 39 | /**
|
34 | 40 | * Central class for interacting with Bintray's REST API.
|
35 | 41 | *
|
@@ -64,25 +70,29 @@ public BintrayService(RestTemplateBuilder builder, BintrayProperties bintrayProp
|
64 | 70 | }
|
65 | 71 |
|
66 | 72 | public boolean isDistributionComplete(ReleaseInfo releaseInfo) {
|
67 |
| - RequestEntity<Void> publishedFilesRequest = getRequest(releaseInfo, 0); |
68 | 73 | RequestEntity<Void> allFilesRequest = getRequest(releaseInfo, 1);
|
69 |
| - Object[] allFiles = this.restTemplate.exchange(allFilesRequest, Object[].class).getBody(); |
70 |
| - int count = 0; |
71 |
| - while (count < 120) { |
72 |
| - Object[] publishedFiles = this.restTemplate.exchange(publishedFilesRequest, Object[].class).getBody(); |
73 |
| - int unpublished = allFiles.length - publishedFiles.length; |
74 |
| - if (unpublished == 0) { |
75 |
| - return true; |
76 |
| - } |
77 |
| - count++; |
| 74 | + Object[] allFiles = waitAtMost(5, TimeUnit.MINUTES).with().pollDelay(20, TimeUnit.SECONDS).until(() -> { |
78 | 75 | try {
|
79 |
| - Thread.sleep(20000); |
| 76 | + return this.restTemplate.exchange(allFilesRequest, Object[].class).getBody(); |
80 | 77 | }
|
81 |
| - catch (InterruptedException e) { |
82 |
| - |
| 78 | + catch (HttpClientErrorException ex) { |
| 79 | + if (ex.getStatusCode() != HttpStatus.NOT_FOUND) { |
| 80 | + throw ex; |
| 81 | + } |
| 82 | + return null; |
83 | 83 | }
|
| 84 | + }, Objects::nonNull); |
| 85 | + RequestEntity<Void> publishedFilesRequest = getRequest(releaseInfo, 0); |
| 86 | + try { |
| 87 | + waitAtMost(40, TimeUnit.MINUTES).with().pollDelay(20, TimeUnit.SECONDS).until(() -> { |
| 88 | + Object[] publishedFiles = this.restTemplate.exchange(publishedFilesRequest, Object[].class).getBody(); |
| 89 | + return allFiles.length == publishedFiles.length; |
| 90 | + }); |
| 91 | + } |
| 92 | + catch (ConditionTimeoutException ex) { |
| 93 | + return false; |
84 | 94 | }
|
85 |
| - return false; |
| 95 | + return true; |
86 | 96 | }
|
87 | 97 |
|
88 | 98 | private RequestEntity<Void> getRequest(ReleaseInfo releaseInfo, int includeUnpublished) {
|
|
0 commit comments