Add wait and retry for API Football minute rate limit

This commit is contained in:
2021-01-11 10:28:33 +01:00
parent 221a2157cf
commit 0578c6ecbc

View File

@@ -2,7 +2,6 @@ package de.jeyp91.apifootball;
import de.jeyp91.ResourceProvider;
import de.jeyp91.S3Provider;
import de.jeyp91.teamidmatcher.TeamIDMatcher;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@@ -31,7 +30,20 @@ public class APIFootballUpdater {
S3Provider prov = new S3Provider();
prov.writeFixturesToS3(league, content);
} catch (Exception e) {
logger.error(e.getMessage());
if(e.getMessage().endsWith("did not have any results with status: 'Too many requests. Your rate limit is 10 requests per minute.")) {
try {
Thread.sleep(1000 * 60);
String content = getRawData(apiFootballUrl);
S3Provider prov = new S3Provider();
prov.writeFixturesToS3(league, content);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
} catch (Exception exception) {
logger.error(e.getMessage());
}
} else {
logger.error(e.getMessage());
}
}
}