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:
ryanhamshire 2014-12-11 14:48:34 -08:00
parent 9aeaa5a574
commit 3c3506bf55

View File

@ -96,10 +96,35 @@ class UUIDFetcher {
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++)
{
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
writeBody(connection, body);
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
boolean retry = false;
JSONArray array = null;
do
{
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
writeBody(connection, body);
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) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");