Skip to content

Commit

Permalink
add some sleep when waiting for the export, improve logging and adjus…
Browse files Browse the repository at this point in the history
…t readme
  • Loading branch information
jckleiner committed Dec 23, 2023
1 parent 672fecb commit 9ba9a9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Create a `.env` file with the following properties ([How do I find all these val
PCLOUD_API_HOST=
PCLOUD_FOLDER_ID=

# if you don't use the Docker image and want to download the backup to a different folder
# DOWNLOADS_DIRECTORY_PATH=<absolute-folder-path>

### Backup to Cloud With Docker

Once you created your `.env` file, you can run the following command to start your backup:
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/greydev/notionbackup/NotionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ private Optional<String> triggerExportTask() throws IOException, InterruptedExce
}
*/
if (responseJsonNode.get("taskId") == null) {
log.error("Error name: {}, error message: {}", responseJsonNode.get("name"), responseJsonNode.get("message"));
JsonNode errorName = responseJsonNode.get("name");
log.error("Error name: {}, error message: {}", errorName, responseJsonNode.get("message"));
if (StringUtils.equalsIgnoreCase(errorName.toString(), "UnauthorizedError")) {
log.error("UnauthorizedError: seems like your token is not valid anymore. Try to log in to Notion again and replace you old token.");
}
return Optional.empty();
}

Expand All @@ -201,10 +205,9 @@ private Optional<String> getDownloadLink(String taskId) throws IOException, Inte
.POST(HttpRequest.BodyPublishers.ofString(postBody))
.build();

for (int i = 0; i < 8000; i++) {
for (int i = 0; i < 800; i++) {
HttpResponse<String> response = newClient.send(request, HttpResponse.BodyHandlers.ofString());

// TODO Need to prepare Jackson Document and see how this is handled. I don't wan't this wrapper "Results" class
Results results = objectMapper.readValue(response.body(), Results.class);

if (results.getResults().isEmpty()) {
Expand Down Expand Up @@ -232,6 +235,7 @@ private Optional<String> getDownloadLink(String taskId) throws IOException, Inte
log.info("Notion API workspace export 'state': '{}', Pages exported so far: {}", result.getState(), result.getStatus().getPagesExported());
return Optional.of(result.getStatus().getExportUrl());
}
sleep(6000);
}

log.info("Notion workspace export failed. After waiting 80 minutes, the export status from the Notion API response was still not 'success'");
Expand Down

0 comments on commit 9ba9a9b

Please sign in to comment.