Skip to content

Commit

Permalink
Handle socket errors while updating logging dataset
Browse files Browse the repository at this point in the history
Apparently this sometimes happens to Chicago; let's give it a few
retries before giving up entirely.
  • Loading branch information
rjmac committed Sep 5, 2017
1 parent c2123ed commit 68be75c
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/main/java/com/socrata/datasync/job/IntegrationJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import com.sun.jersey.api.client.ClientHandlerException;

import java.io.BufferedInputStream;
import java.io.File;
Expand All @@ -33,6 +34,7 @@
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -387,13 +389,34 @@ public static String addLogEntry(final String logDatasetID, final SocrataConnect
upsertObjects.add(ImmutableMap.copyOf(newCols));

String logPublishingErrorMessage = null;
try {
producer.upsert(logDatasetID, upsertObjects);
}
catch (SodaError | InterruptedException e) {
e.printStackTrace();
logPublishingErrorMessage = e.getMessage();
}

int retryLimit = 10;
boolean retry;
do {
retry = false;
try {
producer.upsert(logDatasetID, upsertObjects);
}
catch (SodaError | InterruptedException e) {
e.printStackTrace();
logPublishingErrorMessage = e.getMessage();
}
catch (ClientHandlerException e) {
if(e.getCause() instanceof SocketException) {
System.out.println("Socket exception while updating logging dataset: " + e.getCause().getMessage());
if(retryLimit-- > 0) {
System.out.println("Retrying");
retry = true;
} else {
e.printStackTrace();
logPublishingErrorMessage = e.getMessage();
}
} else {
throw e;
}
}
} while(retry);

return logPublishingErrorMessage;
}

Expand Down

0 comments on commit 68be75c

Please sign in to comment.