Added retry logic to UUID migration.
Finally got a detailed log from hitting a rate limit - added retry logic for only the cases where it's definitely a rate limit problem.
This commit is contained in:
parent
9aeaa5a574
commit
3c3506bf55
|
|
@ -95,11 +95,36 @@ class UUIDFetcher {
|
||||||
|
|
||||||
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
||||||
for (int i = 0; i < requests; i++)
|
for (int i = 0; i < requests; i++)
|
||||||
|
{
|
||||||
|
boolean retry = false;
|
||||||
|
JSONArray array = null;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
HttpURLConnection connection = createConnection();
|
HttpURLConnection connection = createConnection();
|
||||||
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
||||||
writeBody(connection, body);
|
writeBody(connection, body);
|
||||||
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
retry = false;
|
||||||
|
array = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
//in case of error 429 too many requests, pause and then retry later
|
||||||
|
if(e.getMessage().contains("429"))
|
||||||
|
{
|
||||||
|
retry = true;
|
||||||
|
GriefPrevention.AddLogEntry("Mojang says we're sending requests too fast. Will retry every 30 seconds until we succeed...");
|
||||||
|
Thread.sleep(30000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while(retry);
|
||||||
|
|
||||||
for (Object profile : array) {
|
for (Object profile : array) {
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
JSONObject jsonProfile = (JSONObject) profile;
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = (String) jsonProfile.get("id");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user