Skip to content

Commit

Permalink
fix: retry listing folders
Browse files Browse the repository at this point in the history
  • Loading branch information
crepererum committed Oct 4, 2023
1 parent b563f1c commit a8e107c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/commands/list_folders.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::{collections::HashSet, time::Duration};

use anyhow::{anyhow, ensure, Context, Result};
use thirtyfour::{By, WebDriver, WebElement};
Expand All @@ -7,6 +7,26 @@ use tracing::debug;
use crate::thirtyfour_util::FindExt;

pub async fn list_folders(webdriver: &WebDriver) -> Result<Vec<(WebElement, String)>> {
tokio::time::timeout(Duration::from_secs(20), async {
loop {
let folders = list_folders_inner(webdriver).await?;

if folders.is_empty() {
debug!("folders empty, waiting");

tokio::time::sleep(Duration::from_millis(100)).await;
} else {
debug!("found folders");

return Ok(folders);
}
}
})
.await
.context("no timeout")?
}

async fn list_folders_inner(webdriver: &WebDriver) -> Result<Vec<(WebElement, String)>> {
let folder_column = webdriver
.find_one(By::ClassName("folder-column"))
.await
Expand Down Expand Up @@ -41,8 +61,5 @@ pub async fn list_folders(webdriver: &WebDriver) -> Result<Vec<(WebElement, Stri
folders.push((anchor, title));
}

ensure!(!folders.is_empty(), "list of folders should never be empty");
debug!("found folders");

Ok(folders)
}

0 comments on commit a8e107c

Please sign in to comment.