handle time outs doing vsac import (starlink obstructions)

This commit is contained in:
Grahame Grieve 2024-04-25 21:58:42 +10:00
parent 46bdec9054
commit 5118c26ee4
1 changed files with 69 additions and 47 deletions

View File

@ -114,15 +114,22 @@ public class VSACImporter extends OIDBasedValueSetImporter {
private boolean processOid(String dest, boolean onlyNew, Map<String, String> errs, FHIRToolingClient fhirToolingClient, String oid)
throws IOException, InterruptedException, FileNotFoundException {
while (true) {
boolean ok = true;
long t = System.currentTimeMillis();
ValueSet vs = null;
try {
vs = fhirToolingClient.read(ValueSet.class, oid);
} catch (Exception e) {
if (e.getMessage().contains("timed out")) {
ok = false;
} else {
errs.put(oid, "Read: " +e.getMessage());
System.out.println("Read "+oid+" failed @ "+Utilities.describeDuration(System.currentTimeMillis()-t)+"ms: "+e.getMessage());
return false;
}
}
if (ok) {
t = System.currentTimeMillis();
try {
Parameters p = new Parameters();
@ -130,9 +137,16 @@ public class VSACImporter extends OIDBasedValueSetImporter {
ValueSet vse = fhirToolingClient.expandValueset(null, p);
vs.setExpansion(vse.getExpansion());
} catch (Exception e) {
if (e.getMessage().contains("timed out")) {
ok = false;
} else {
errs.put(oid, "Expansion: " +e.getMessage());
System.out.println("Expand "+oid+" failed @ "+Utilities.describeDuration(System.currentTimeMillis()-t)+"ms: "+e.getMessage());
return false;
}
}
}
if (ok) {
while (isIncomplete(vs.getExpansion())) {
Parameters p = new Parameters();
int offset = vs.getExpansion().getParameter("offset").getValueIntegerType().getValue() + vs.getExpansion().getParameter("count").getValueIntegerType().getValue();
@ -144,14 +158,21 @@ public class VSACImporter extends OIDBasedValueSetImporter {
vs.getExpansion().getContains().addAll(vse.getExpansion().getContains());
vs.getExpansion().setParameter(vse.getExpansion().getParameter());
} catch (Exception e2) {
if (e2.getMessage().contains("timed out")) {
ok = false;
break;
} else {
errs.put(oid, "Expansion: " +e2.getMessage()+" @ "+offset);
System.out.println("Expand "+oid+" @ "+offset+" failed @ "+Utilities.describeDuration(System.currentTimeMillis()-t)+"ms: "+e2.getMessage());
return false;
}
}
}
}
if (ok) {
vs.getExpansion().setOffsetElement(null);
vs.getExpansion().getParameter().clear();
if (vs.hasTitle()) {
if (vs.getTitle().equals(vs.getDescription())) {
vs.setTitle(vs.getName());
@ -170,9 +191,10 @@ public class VSACImporter extends OIDBasedValueSetImporter {
vs.setName(makeValidName(vs.getName()));
JurisdictionUtilities.setJurisdictionCountry(vs.getJurisdiction(), "US");
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path(dest, "ValueSet-" + oid + ".json")), vs);
return true;
}
}
}
private boolean isIncomplete(ValueSetExpansionComponent expansion) {
IntegerType c = expansion.getParameter("count") != null ? expansion.getParameter("count").getValueIntegerType() : new IntegerType(0);