-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry logic for upload call (#26)
Description =========== It happens quite often that the binary upload call fails with an error in the 500 range. I have no real idea what the root cause is since it's a server error. Maybe the inital `createUploadResource` resource call is to blame. This patch adds a simple retry logic around the upload task to check if our errors go down when we try to redo the call a few times with a timeout in between. The values for retryCount and retryTimeout can be passed as usual via properties, env or directly in script. | property | gradle property name | environment variable | | --------------------- | --------------------------------- | ----------------------------------- | | retryCount | `appCenter.retryCount` | `APP_CENTER_RETRY_COUNT` | | retryTimeout | `appCenter.retryTimeout` | `APP_CENTER_RETRY_TIMEOUT` | The default values are `3` for the `retryCount` and `5` seconds for the `retryTimeout`. To test the logic I had to split the actual call into a helper method. It would be cleaner to also move the other methods over but I treat this change as a temp fix than a proper implemenation. Maybe I roll this back ... Changes ======= * ![ADD] retry logic for upload call
- Loading branch information
Showing
10 changed files
with
261 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/groovy/wooga/gradle/appcenter/api/AppCenterRest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package wooga.gradle.appcenter.api | ||
|
||
import org.apache.http.HttpEntity | ||
import org.apache.http.HttpResponse | ||
import org.apache.http.client.HttpClient | ||
import org.apache.http.client.methods.HttpPost | ||
import org.apache.http.entity.mime.MultipartEntityBuilder | ||
import org.apache.http.entity.mime.content.FileBody | ||
import org.gradle.api.GradleException | ||
|
||
import java.util.logging.Logger | ||
|
||
class AppCenterRest { | ||
static Logger logger = Logger.getLogger(AppCenterRest.name) | ||
|
||
static Boolean uploadResources(HttpClient client, String apiToken, String uploadUrl, File binary, Integer retryCount = 0, Long retryTimeout = 0) { | ||
HttpPost post = new HttpPost(uploadUrl) | ||
FileBody ipa = new FileBody(binary) | ||
post.setHeader("X-API-Token", apiToken) | ||
HttpEntity content = MultipartEntityBuilder.create() | ||
.addPart("ipa", ipa) | ||
.build() | ||
|
||
post.setEntity(content) | ||
HttpResponse response = client.execute(post) | ||
|
||
if (response.statusLine.statusCode >= 500) { | ||
logger.warning("unable to upload to provided upload url ${uploadUrl}".toString()) | ||
logger.warning(response.statusLine.reasonPhrase) | ||
|
||
if (retryCount > 0) { | ||
logger.warning("wait and retry after ${(retryTimeout) / 1000} s".toString()) | ||
sleep(retryTimeout) | ||
return uploadResources(client, apiToken, uploadUrl, binary, retryCount - 1, retryTimeout) | ||
} | ||
} | ||
|
||
if (response.statusLine.statusCode != 204) { | ||
throw new GradleException("unable to upload to provided upload url ${uploadUrl}" + response.statusLine.toString()) | ||
} | ||
|
||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.