Skip to content

Commit

Permalink
Merge pull request #177 from socrata/rjm/handle-socket-errors-while-u…
Browse files Browse the repository at this point in the history
…pdating-log-dataset-en-14775

Handle socket errors while updating logging dataset
  • Loading branch information
rjmac authored Sep 5, 2017
2 parents 03c862b + 68be75c commit d7fee14
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 d7fee14

Please sign in to comment.