From deb3e47ee9a2139ad05ccfd494dfe0500a5f2a75 Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Wed, 4 Oct 2023 20:17:54 +0200 Subject: [PATCH] fix: retry listing folders --- src/commands/list_folders.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commands/list_folders.rs b/src/commands/list_folders.rs index 05045ec..4fbb52c 100644 --- a/src/commands/list_folders.rs +++ b/src/commands/list_folders.rs @@ -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}; @@ -7,6 +7,23 @@ use tracing::debug; use crate::thirtyfour_util::FindExt; pub async fn list_folders(webdriver: &WebDriver) -> Result> { + 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 { + return Ok(folders); + } + } + }) + .await + .context("no timeout")? +} + +async fn list_folders_inner(webdriver: &WebDriver) -> Result> { let folder_column = webdriver .find_one(By::ClassName("folder-column")) .await