Improved error management

This commit is contained in:
Luca Frosini 2023-01-12 16:32:14 +01:00
parent 4f831f19d7
commit ce30732166
2 changed files with 32 additions and 18 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.common.software.analyser;
import java.io.File;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
@ -115,7 +116,7 @@ public class SoftwareConceptAnalyser {
concept.put(SoftwareConcept.DOI_URL_PROPERTY_NAME, doiURL.toString());
}
}
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
}
} catch (Exception e) {
for(int j=i+1; j<versions.size(); j++) {

View File

@ -160,23 +160,36 @@ public class ZenodoSoftwareVersionPublisher extends SoftwareVersionPublisher {
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
}
//Add depositionFiles
addFilesToDeposition(files);
//Update deposit metadata
updateMetadata();
// Publish the version
publishToZenodo();
for(File file : files) {
if(!file.exists()) {
throw new RuntimeException(file.getAbsolutePath() + "does not exist");
}
try {
while(!file.delete()) {}
}catch (Exception e) {
logger.error("Unable to delete ", file.getAbsolutePath());
try {
//Add depositionFiles
addFilesToDeposition(files);
//Update deposit metadata
updateMetadata();
// Publish the version
publishToZenodo();
}finally {
for(File file : files) {
if(!file.exists()) {
throw new RuntimeException(file.getAbsolutePath() + " does not exist");
}
try {
int i = 0;
while(!file.delete() && i<10) {
int millis = 100;
logger.warn("File {} not deleted at the attemp {}. Retrying in {} milliseconds.", file.getAbsolutePath(), i+1, millis);
++i;
Thread.sleep(millis);
}
if(i==10) {
logger.warn("After {} attemps the file {} was not deleted. Trying using deleteOnExit().", i, file.getAbsolutePath());
file.deleteOnExit();
}
}catch (Exception e) {
logger.error("Unable to delete {}", file.getAbsolutePath());
}
}
}
}