diff --git a/code/cloud_library_export/cloud_library_export.jar b/code/cloud_library_export/cloud_library_export.jar index bc5a4f6332..ba434d1ad6 100644 Binary files a/code/cloud_library_export/cloud_library_export.jar and b/code/cloud_library_export/cloud_library_export.jar differ diff --git a/code/cloud_library_export/src/com/turning_leaf_technologies/cloud_library/CloudLibraryExporter.java b/code/cloud_library_export/src/com/turning_leaf_technologies/cloud_library/CloudLibraryExporter.java index e0c99fffbe..b3dc03727a 100644 --- a/code/cloud_library_export/src/com/turning_leaf_technologies/cloud_library/CloudLibraryExporter.java +++ b/code/cloud_library_export/src/com/turning_leaf_technologies/cloud_library/CloudLibraryExporter.java @@ -404,30 +404,51 @@ 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; } } @@ -435,30 +456,50 @@ CloudLibraryAvailability loadAvailabilityForRecord(String cloudLibraryId) { } 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; } } diff --git a/code/web/release_notes/24.05.00.MD b/code/web/release_notes/24.05.00.MD index e40090b28d..59726182a0 100644 --- a/code/web/release_notes/24.05.00.MD +++ b/code/web/release_notes/24.05.00.MD @@ -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*)