From 69a7cb2832b5b4e7b5aa2af36ced495942a23138 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 6 Nov 2019 19:28:39 +0000 Subject: [PATCH] Change behaviour in case of network failure: finish operation without throwing an exception. Closes #2205 --- .../wikidata/editing/EditBatchProcessor.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/editing/EditBatchProcessor.java b/extensions/wikidata/src/org/openrefine/wikidata/editing/EditBatchProcessor.java index 5c8e98ef7..6f5ec0660 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/editing/EditBatchProcessor.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/editing/EditBatchProcessor.java @@ -163,9 +163,10 @@ public class EditBatchProcessor { } } catch (MediaWikiApiErrorException e) { // TODO find a way to report these errors to the user in a nice way - e.printStackTrace(); + logger.warn("MediaWiki error while editing [" + e.getErrorCode() + + "]: " + e.getErrorMessage()); } catch (IOException e) { - e.printStackTrace(); + logger.warn("IO error while editing: " + e.getMessage()); } batchCursor++; @@ -203,22 +204,29 @@ public class EditBatchProcessor { // Get the current documents for this batch of updates logger.info("Requesting documents"); currentDocs = null; - int retries = 3; + int retries = 5; + int backoff = 2; + int sleepTime = 5000; // TODO: remove currentDocs.isEmpty() once https://github.com/Wikidata/Wikidata-Toolkit/issues/402 is solved while ((currentDocs == null || currentDocs.isEmpty()) && retries > 0) { try { currentDocs = fetcher.getEntityDocuments(qidsToFetch); } catch (MediaWikiApiErrorException e) { - e.printStackTrace(); - Thread.sleep(5000); + logger.warn("MediaWiki error while fetching documents to edit [" + e.getErrorCode() + + "]: " + e.getErrorMessage()); } catch (IOException e) { - e.printStackTrace(); - Thread.sleep(5000); + logger.warn("IO error while fetching documents to edit: " + e.getMessage()); } retries--; + sleepTime *= backoff; + if ((currentDocs == null || currentDocs.isEmpty()) && retries > 0) { + logger.warn("Retrying in " + sleepTime + " ms"); + Thread.sleep(sleepTime); + } } if (currentDocs == null) { - throw new InterruptedException("Fetching current documents failed."); + logger.warn("Giving up on fetching documents to edit. Skipping "+remainingEdits()+" remaining edits."); + globalCursor = scheduled.size(); } batchCursor = 0; }