Skip to content

Commit

Permalink
Add additional error handling and retries during cloudLibrary indexing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdnoble73 committed May 6, 2024
1 parent e398694 commit 3c69259
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 40 deletions.
Binary file modified code/cloud_library_export/cloud_library_export.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -404,61 +404,102 @@ private RecordGroupingProcessor getRecordGroupingProcessor() {
}

CloudLibraryAvailability loadAvailabilityForRecord(String cloudLibraryId) {
int numTries = 0;
boolean callSucceeded = false;
CloudLibraryAvailability availability = new CloudLibraryAvailability();
String apiPath = "/cirrus/library/" + settings.getLibraryId() + "/item/summary/" + cloudLibraryId;

WebServiceResponse response = callCloudLibrary(apiPath);
if (response == null) {
//Something bad happened, we're done.
return null;
} else if (!response.isSuccess()) {
if (response.getResponseCode() != 500) {
logEntry.incErrors("Error " + response.getResponseCode() + " calling " + apiPath + ": " + response.getMessage());
while (!callSucceeded && numTries < 3) {
if (numTries > 0) {
try {
//Sleep a little bit to allow the server to calm down.
Thread.sleep(60000);
} catch (InterruptedException e) {
//Not a big deal if this gets interrupted
}
}
logEntry.addNote("Error getting availability from " + apiPath + ": " + response.getResponseCode() + " " + response.getMessage());
return null;
} else {
availability.setRawResponse(response.getMessage());
CloudLibraryAvailabilityHandler handler = new CloudLibraryAvailabilityHandler(availability);

try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.parse(new ByteArrayInputStream(response.getMessage().getBytes(StandardCharsets.UTF_8)), handler);
} catch (SAXException | ParserConfigurationException | IOException e) {
logger.error("Error parsing response", e);
logEntry.addNote("Error parsing response: " + e);
WebServiceResponse response = callCloudLibrary(apiPath);
if (response == null) {
//Something bad happened, we're done.
} else if (!response.isSuccess()) {
if (numTries == 2) {
if (response.getResponseCode() != 500) {
logEntry.incErrors("Error getting availability " + response.getResponseCode() + " calling " + apiPath + ": " + response.getMessage());
}else {
logEntry.addNote("Error getting availability from " + apiPath + ": " + response.getResponseCode() + " " + response.getMessage());
}
}else{
logger.info("Error getting availability from " + apiPath + ": " + response.getResponseCode());
}
} else {
callSucceeded = true;
availability.setRawResponse(response.getMessage());
CloudLibraryAvailabilityHandler handler = new CloudLibraryAvailabilityHandler(availability);

try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.parse(new ByteArrayInputStream(response.getMessage().getBytes(StandardCharsets.UTF_8)), handler);
} catch (SAXException | ParserConfigurationException | IOException e) {
logger.error("Error parsing response", e);
logEntry.addNote("Error parsing response: " + e);
}
}
numTries++;
if (numTries == 3 && !callSucceeded) {
logEntry.incErrors("Did not get a successful API response after 3 tries for " + settings.getBaseUrl() + apiPath);
break;
}
}

return availability;
}

CloudLibraryAvailabilityType loadAvailabilityTypeForRecord(String cloudLibraryId) {
int numTries = 0;
boolean callSucceeded = false;
CloudLibraryAvailabilityType availabilityType = new CloudLibraryAvailabilityType();
String apiPath = "/cirrus/library/" + settings.getLibraryId() + "/circulation/item/" + cloudLibraryId;

WebServiceResponse response = callCloudLibrary(apiPath);
if (response == null) {
//Something bad happened, we're done.
return null;
} else if (!response.isSuccess()) {
if (response.getResponseCode() != 500) {
logEntry.incErrors("Error " + response.getResponseCode() + " calling " + apiPath + ": " + response.getMessage());
while (!callSucceeded && numTries < 3) {
if (numTries > 0) {
try {
//Sleep a little bit to allow the server to calm down.
Thread.sleep(60000);
} catch (InterruptedException e) {
//Not a big deal if this gets interrupted
}
}
logEntry.addNote("Error getting availability from " + apiPath + ": " + response.getResponseCode() + " " + response.getMessage());
return null;
} else {
availabilityType.setRawResponse(response.getMessage());
CloudLibraryAvailabilityTypeHandler handler = new CloudLibraryAvailabilityTypeHandler(availabilityType);

try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.parse(new ByteArrayInputStream(response.getMessage().getBytes(StandardCharsets.UTF_8)), handler);
} catch (SAXException | ParserConfigurationException | IOException e) {
logger.error("Error parsing response", e);
logEntry.addNote("Error parsing response: " + e);
WebServiceResponse response = callCloudLibrary(apiPath);
if (response == null) {
//Something bad happened, we're done.
} else if (!response.isSuccess()) {
if (numTries == 2) {
if (response.getResponseCode() != 500) {
logEntry.incErrors("Error getting availability type " + response.getResponseCode() + " calling " + apiPath + ": " + response.getMessage());
} else {
logEntry.addNote("Error getting availability type from " + apiPath + ": " + response.getResponseCode() + " " + response.getMessage());
}
}else{
logger.info("Error getting availability type from " + apiPath + ": " + response.getResponseCode());
}
} else {
availabilityType.setRawResponse(response.getMessage());
CloudLibraryAvailabilityTypeHandler handler = new CloudLibraryAvailabilityTypeHandler(availabilityType);

try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
saxParser.parse(new ByteArrayInputStream(response.getMessage().getBytes(StandardCharsets.UTF_8)), handler);
} catch (SAXException | ParserConfigurationException | IOException e) {
logger.error("Error parsing response", e);
logEntry.addNote("Error parsing response: " + e);
}
}
numTries++;
if (numTries == 3 && !callSucceeded) {
logEntry.incErrors("Did not get a successful API response after 3 tries for " + settings.getBaseUrl() + apiPath);
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions code/web/release_notes/24.05.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
### cloudLibrary Updates
- Additional checking for cloudLibrary records that should have a format of eComic based on 650 fields. (*MDN*)
- Error handling when viewing cloudLibrary staff view. (*MDN*)
- Add additional error handling and retries during cloudLibrary indexing. (*MDN*)

### Data Protection Updates
- Fixed issue where Cookie Consent banner would not disappear while not logged in, regardless of cookie preferences. (*JOM*)
Expand Down

0 comments on commit 3c69259

Please sign in to comment.