Skip to content

Commit 823f097

Browse files
ReidWebPricetx
authored andcommitted
Changed 'wait time' for retries to increase depending on number of attempts made to load page. (#17)
1 parent 4e80c8c commit 823f097

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.3.4
2+
======
3+
* Changed 'wait time' for retries to increase depending on number of attempts made to load page.
4+
15
v1.3.3
26
======
37
* If the Gatherer experiences a HTTP error code `429` (Too many requests), it will pause for 1-20 milliseconds and retry via recursive method call.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.ffxivcensus.gatherer</groupId>
88
<artifactId>XIVStats-Gatherer-Java</artifactId>
9-
<version>v1.3.3</version>
9+
<version>v1.3.4</version>
1010
<name>XIVStats Lodestone Gatherer</name>
1111
<url>https://github.com/xivstats</url>
1212

src/main/java/com/ffxivcensus/gatherer/Gatherer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void run() {
3535
System.out.println("Starting evaluation of player ID: " +nextID);
3636
}
3737
//Parse players and write them to DB
38-
String out = parent.writeToDB(Player.getPlayer(nextID));
38+
String out = parent.writeToDB(Player.getPlayer(nextID, 1));
3939
if (!parent.isQuiet()) { //If not running in quiet mode
4040
System.out.println(out);
4141
}
@@ -49,7 +49,7 @@ public void run() {
4949
}
5050
//Then attempt to write again
5151
try {
52-
String out = parent.writeToDB(Player.getPlayer(nextID));
52+
String out = parent.writeToDB(Player.getPlayer(nextID,1));
5353
if (!parent.isQuiet()) {
5454
System.out.println(out);
5555
}
@@ -68,4 +68,3 @@ public void run() {
6868

6969
}
7070

71-

src/main/java/com/ffxivcensus/gatherer/Player.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,10 +1853,11 @@ public boolean doesPlayerHaveMinion(String minionName) {
18531853
* Fetch a player from the lodestone specified by ID.
18541854
*
18551855
* @param playerID the ID of the player to fetch
1856+
* @param attempt the number of times this character has been attempted.
18561857
* @return the player object matching the specified ID.
18571858
* @throws Exception exception thrown if more class levels returned than anticipated.
18581859
*/
1859-
public static Player getPlayer(int playerID) throws Exception {
1860+
public static Player getPlayer(int playerID, int attempt) throws Exception {
18601861
//Initialize player object to return
18611862
Player player = new Player(playerID);
18621863
//Declare HTML document
@@ -1923,13 +1924,14 @@ public static Player getPlayer(int playerID) throws Exception {
19231924
String strEx = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(ioEx);
19241925
String statusCode = strEx.split("\\s+")[5].replace("Status=","").replace(",","");
19251926
if(statusCode.equals("429")) {
1926-
//Generate random number 1-20 and sleep for it
1927+
//Generate random number 1->20*attempt no and sleep for it
19271928
Random rand = new Random();
1928-
1929-
int randomNum = rand.nextInt((20 - 1) + 1) + 1;
1930-
System.out.println("Experiencing rate limiting (HTTP 429) while fetching id " + playerID + ", waiting " + randomNum + "ms then retrying...");
1929+
int max = attempt * 20;
1930+
int min = (attempt - 1) + 1;
1931+
int randomNum = rand.nextInt(max - min + 1) + min;
1932+
System.out.println("Experiencing rate limiting (HTTP 429) while fetching id " + playerID + " (attempt " + attempt + "), waiting " + randomNum + "ms then retrying...");
19311933
TimeUnit.MILLISECONDS.sleep(randomNum);
1932-
player = Player.getPlayer(playerID);
1934+
player = Player.getPlayer(playerID, ++attempt);
19331935
} else {
19341936
throw new Exception("Character " + playerID + " does not exist. Status: " + statusCode);
19351937
}
@@ -2423,4 +2425,4 @@ public int getBitHasVath() {
24232425
public void setHasVath(boolean hasVath) {
24242426
this.hasVath = hasVath;
24252427
}
2426-
}
2428+
}

src/test/java/com/ffxivcensus/gatherer/PlayerTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PlayerTest {
2121
@org.junit.Test
2222
public void testGetPlayer() throws Exception {
2323
//Fetch object to test against (Aelia Sokoto, Cerberus)
24-
Player playerOne = Player.getPlayer(2356533);
24+
Player playerOne = Player.getPlayer(2356533,1);
2525

2626
//NOTE: All of the following tests assume various pieces of information
2727
//Testing information that is very unlikely to change
@@ -167,7 +167,7 @@ public void testGetPlayer() throws Exception {
167167
*/
168168
@org.junit.Test
169169
public void testGetVeteranPlayer() throws Exception {
170-
Player player = Player.getPlayer(501646);
170+
Player player = Player.getPlayer(501646,1);
171171

172172
//Player has 960 days sub, make sure recorded correctly
173173
assertTrue(player.isHas960DaysSub());
@@ -187,7 +187,7 @@ public void testGetVeteranPlayer() throws Exception {
187187
*/
188188
@org.junit.Test
189189
public void testUnplayedPlayer() throws Exception {
190-
Player player = Player.getPlayer(13002142);
190+
Player player = Player.getPlayer(13002142,1);
191191

192192
//Test grand company
193193
assertEquals("none", player.getGrandCompany());
@@ -240,7 +240,7 @@ public void testUnplayedPlayer() throws Exception {
240240
*/
241241
@org.junit.Test
242242
public void testGetPlayerNoGCHasFC() throws Exception {
243-
Player player = Player.getPlayer(1);
243+
Player player = Player.getPlayer(1,1);
244244

245245
//Verify that grand company is "None"
246246
assertEquals("none", player.getGrandCompany());
@@ -254,7 +254,7 @@ public void testGetPlayerNoGCHasFC() throws Exception {
254254
*/
255255
@org.junit.Test
256256
public void testGetPlayerNoFCHasGC() throws Exception {
257-
Player player = Player.getPlayer(11886920);
257+
Player player = Player.getPlayer(11886920,1);
258258

259259
//Test that GC is maelstrom
260260
assertEquals("Maelstrom", player.getGrandCompany());
@@ -270,7 +270,7 @@ public void testGetPlayerNoFCHasGC() throws Exception {
270270
*/
271271
@org.junit.Test
272272
public void testGetPlayerWithAllCollectibles() throws Exception {
273-
Player player = Player.getPlayer(71);
273+
Player player = Player.getPlayer(71,1);
274274

275275
assertEquals(player.getBitHasArrArtbook(), 1);
276276
assertEquals(player.getBitHasBeforeMeteor(), 1);
@@ -287,12 +287,12 @@ public void testGetPlayerWithAllCollectibles() throws Exception {
287287
public void testGetPlayerInvalid() {
288288
try {
289289
//Try to get a character that doesn't exist
290-
Player player = Player.getPlayer(2356539);
290+
Player player = Player.getPlayer(2356539,1);
291291
//If no exception thrown fail
292292
fail("Character should not exist");
293293
} catch (Exception e) {
294294

295295
}
296296
}
297297

298-
}
298+
}

0 commit comments

Comments
 (0)