This commit is contained in:
@@ -5,32 +5,38 @@ 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) -> ! {
|
||||
pub async fn update_wsdc(bot: Bot, fetcher: DynWsdcFetcher) -> ! {
|
||||
loop {
|
||||
update_all_teachers(&bot).await;
|
||||
update_all_teachers(&bot, fetcher.clone()).await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates all teachers once
|
||||
async fn update_all_teachers(bot: &Bot) {
|
||||
let mut l = index_wsdc_ids(bot).await;
|
||||
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).await;
|
||||
process_page(wait_duration, index, page, fetcher.clone()).await;
|
||||
}
|
||||
tracing::info!("Updates all pages");
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(page, wait_duration))]
|
||||
async fn process_page(wait_duration: Duration, index: u32, page: mwbot::Page) {
|
||||
#[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).await {
|
||||
match generate_page(index, page, fetcher).await {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
tracing::error!("Error updating: {err}");
|
||||
|
||||
Reference in New Issue
Block a user