Skip to content

Commit

Permalink
Fix error handling with failing pid service
Browse files Browse the repository at this point in the history
Previously when updating a pid failed after uploading an archive, the
error was basically ignored and not logged.
  • Loading branch information
joschrew committed Oct 27, 2023
1 parent 9e33c0f commit d5988d4
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,33 +317,50 @@ public void run() {
IndexingConfig conf = readSearchindexFilegrps(destination, bagInfos, requestParams);
sendToElastic(pid, conf);
} catch (Exception ex) {
logger.error("Archive Import failed", ex);
handleFailedImport(ex, pid, importResult, info);
} finally {
// Clean up the temp: Files are saved in CDStar and not needed any more
FileSystemUtils.deleteRecursively(new File(tempDir));
}
}

private void handleFailedImport(Exception ex, String pid, ImportResult importResult,
TrackingInfo info) {
private void handleFailedImport(
Exception ex, String pid, ImportResult importResult,TrackingInfo info
) {
// Delete the PID
try {
// Delete the PID
pidService.deletePid(pid);
} catch (Exception e) {
logger.error(
"error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}", pid,
importResult.getOnlineId(), importResult.getOfflineId(), e,
"Deleting PID failed"
);
}

// Delete the archive
if (importResult != null) {
// Delete the archives
if (importResult != null) {
try {
archiveManagerService.deleteArchive(importResult.getOnlineId(), null);
} catch(Exception e) {
logger.error(
"error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}",
pid, importResult.getOnlineId(), importResult.getOfflineId(), e,
"Deleting online archive failed"
);
}
try {
archiveManagerService.deleteArchive(importResult.getOfflineId(), null);
} catch (Exception e) {
logger.error(
"error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}' - {}",
pid, importResult.getOnlineId(), importResult.getOfflineId(), e,
"Deleting offline archive failed"
);
}

} catch (IOException e) {
// if cleaning fails, nothing can be done than manually clean up
logger.error("error cleaning up. pid: '{}', online-id: '{}', offline-id: '{}'", pid,
importResult.getOnlineId(), importResult.getOfflineId(), e);
}

logger.error(ex.getMessage(), ex);

// Save the failure data to the tracking database
info.setStatus(TrackingStatus.FAILED);
info.setMessage(ex.getMessage());
Expand Down

0 comments on commit d5988d4

Please sign in to comment.