46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
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};
|
|
use crate::fetching::DynWsdcFetcher;
|
|
|
|
pub async fn update_wsdc(bot: Bot, fetcher: DynWsdcFetcher) -> ! {
|
|
loop {
|
|
update_all_teachers(&bot, fetcher.clone()).await;
|
|
}
|
|
}
|
|
|
|
/// Updates all teachers once
|
|
async fn update_all_teachers(bot: &Bot, fetcher: DynWsdcFetcher) {
|
|
let mut l = index_wsdc_ids(bot, fetcher.clone()).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, fetcher.clone()).await;
|
|
}
|
|
tracing::info!("Updates all pages");
|
|
}
|
|
|
|
#[tracing::instrument(skip(page, wait_duration, fetcher))]
|
|
async fn process_page(
|
|
wait_duration: Duration,
|
|
index: u32,
|
|
page: mwbot::Page,
|
|
fetcher: DynWsdcFetcher,
|
|
) {
|
|
tracing::info!("Next up");
|
|
sleep(wait_duration).await;
|
|
|
|
match generate_page(index, page, fetcher).await {
|
|
Ok(()) => (),
|
|
Err(err) => {
|
|
tracing::error!("Error updating: {err}");
|
|
}
|
|
}
|
|
}
|