Skip to content

Commit

Permalink
fix: remove un-needed code to check for json exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Oct 21, 2023
1 parent 63b5520 commit c26501c
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ private boolean processApi() throws UpdateException {
final String key = settings.getString(Settings.KEYS.NVD_API_KEY);
if (key != null) {
builder.withApiKey(key)
.withDelay(3000)
.withDelay(2500)
.withThreadCount(4);
} else {
LOGGER.warn("An NVD API Key was not provided - it is highly recommended to use an NVD API key as the update can take a VERY long time without an API Key");
builder.withDelay(8000);
}
long delay = 0;
try {
Expand All @@ -282,24 +285,25 @@ private boolean processApi() throws UpdateException {
processingExecutorService = Executors.newFixedThreadPool(PROCESSING_THREAD_POOL_SIZE);
final List<Future<NvdApiProcessor>> submitted = new ArrayList<>();
int errorCount = 0;
int max = -1;
int ctr = 0;
try (NvdCveClient api = builder.build()) {
while (api.hasNext()) {
try {
final Collection<DefCveItem> items = api.next();
if (items != null && !items.isEmpty()) {
final Future<NvdApiProcessor> f = processingExecutorService.submit(new NvdApiProcessor(cveDb, items));
submitted.add(f);
errorCount = 0;
}
} catch (NvdApiException ex) {
if (ex.getCause() instanceof JsonProcessingException) {
errorCount += 1;
if (errorCount > 10) {
throw ex;
}
} else {
throw ex;
final Collection<DefCveItem> items = api.next();
max = api.getTotalAvailable();
if (ctr == 0) {
LOGGER.info(String.format("NVD API has %,d records in this update", max));
}
if (items != null && !items.isEmpty()) {
final Future<NvdApiProcessor> f = processingExecutorService.submit(new NvdApiProcessor(cveDb, items));
submitted.add(f);
errorCount = 0;
ctr += 1;
if ((ctr % 10) == 0) {
double percent = (double) (ctr * 2000) / max * 100;
LOGGER.info(String.format("Processing %,d/%,d (%.0f%%)", ctr * 2000, max, percent));
}

}
}
lastModifiedRequest = api.getLastUpdated();
Expand Down

0 comments on commit c26501c

Please sign in to comment.