Made tracing calls more complicated, structured code a little different

This commit is contained in:
Lukas Wölfer
2025-09-03 02:08:43 +02:00
parent 004f0eb900
commit bb88e68f8f
3 changed files with 131 additions and 95 deletions

View File

@@ -2,23 +2,38 @@ use std::time::Duration;
use mwbot::Bot;
use rand::seq::SliceRandom as _;
use tokio::time::sleep;
use crate::{watchdog::generate_page, wikiinfo::index_wsdc_ids};
pub async fn update_wsdc(bot: Bot) -> ! {
loop {
let mut l = index_wsdc_ids(&bot).await;
l.shuffle(&mut rand::rng());
tracing::info!("We have to update {} pages", l.len());
let wait_duration = Duration::from_secs(6 * 3600);
for (index, page) in l {
tracing::info!("Next up: #{index}");
tokio::time::sleep(wait_duration).await;
if generate_page(index, page).await {
tracing::info!("Updated {index}");
} else {
tracing::error!("Error updating {index}");
}
update_all_teachers(&bot).await;
}
}
/// Updates all teachers once
async fn update_all_teachers(bot: &Bot) {
let mut l = index_wsdc_ids(bot).await;
l.shuffle(&mut rand::rng());
tracing::info!("We have to update {} pages", l.len());
let wait_duration = Duration::from_hours(6);
for (index, page) in l {
process_page(wait_duration, index, page).await;
}
tracing::info!("Updates all pages");
}
#[tracing::instrument(skip_all, fields(index))]
async fn process_page(wait_duration: Duration, index: u32, page: mwbot::Page) {
tracing::info!("Next up");
sleep(wait_duration).await;
match generate_page(index, page).await {
Ok(()) => (),
Err(err) => {
tracing::error!("Error updating: {err}");
}
}
}