Failsafe ignore already failed id generations
This commit is contained in:
@@ -49,31 +49,42 @@ fn page_from_info(info: DanceInfo) -> Result<Wikicode, InfoCompileError> {
|
|||||||
pub async fn watch_wanted(bot: Bot) {
|
pub async fn watch_wanted(bot: Bot) {
|
||||||
let span = tracing::span!(Level::INFO, "wanted_watchdog");
|
let span = tracing::span!(Level::INFO, "wanted_watchdog");
|
||||||
let _enter = span.enter();
|
let _enter = span.enter();
|
||||||
loop {
|
|
||||||
tracing::info!("Watchdog check...");
|
|
||||||
let wanted = wanted_ids(bot.clone()).await;
|
|
||||||
|
|
||||||
for (id, page) in wanted {
|
let mut ignored_ids = vec![];
|
||||||
generate_page(id, page).await;
|
loop {
|
||||||
|
if ignored_ids.is_empty() {
|
||||||
|
tracing::info!("Watchdog check...");
|
||||||
|
} else {
|
||||||
|
tracing::info!("Watchdog check [{} failed ids]...", ignored_ids.len());
|
||||||
|
}
|
||||||
|
let wanted = wanted_ids(bot.clone()).await;
|
||||||
|
let mut new_ignored = vec![];
|
||||||
|
for (id, page) in wanted.into_iter().filter(|(x, _)| ignored_ids.contains(x)) {
|
||||||
|
if !generate_page(id, page).await {
|
||||||
|
new_ignored.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !new_ignored.is_empty() {
|
||||||
|
ignored_ids.extend(new_ignored);
|
||||||
}
|
}
|
||||||
tokio::time::sleep(Duration::from_secs(30)).await;
|
tokio::time::sleep(Duration::from_secs(30)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_page(id: u32, page: mwbot::Page) {
|
async fn generate_page(id: u32, page: mwbot::Page) -> bool {
|
||||||
tracing::info!("Taking care of {id}");
|
tracing::info!("Taking care of {id}");
|
||||||
let info = match fetch_wsdc_info(id).await {
|
let info = match fetch_wsdc_info(id).await {
|
||||||
Ok(o) => o,
|
Ok(o) => o,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Error fetching wsdc info for {id}: {e}");
|
tracing::error!("Error fetching wsdc info for {id}: {e}");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let code = match page_from_info(info) {
|
let code = match page_from_info(info) {
|
||||||
Ok(o) => o,
|
Ok(o) => o,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Creating wikicode for {id}: {e}");
|
tracing::error!("Creating wikicode for {id}: {e}");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,9 +97,10 @@ async fn generate_page(id: u32, page: mwbot::Page) {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => (),
|
Ok(_) => true,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Could not save page for {id}: {e}");
|
tracing::error!("Could not save page for {id}: {e}");
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user