From 1ad2ac05fa2667e0fcc8cf1f2d1c9bf870dcecf0 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 20 Jul 2024 10:57:25 +0200 Subject: [PATCH] fix(cli): delete users if they got deleted so they wont be retried the next time we start this command --- upub/cli/src/update.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/upub/cli/src/update.rs b/upub/cli/src/update.rs index 6f63d51..05ac9cc 100644 --- a/upub/cli/src/update.rs +++ b/upub/cli/src/update.rs @@ -1,5 +1,5 @@ use futures::TryStreamExt; -use sea_orm::{ActiveModelTrait, ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter}; +use sea_orm::{ActiveModelTrait, ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter, ModelTrait}; use upub::traits::Fetcher; pub async fn update_users(ctx: upub::Context, days: i64, limit: Option) -> Result<(), sea_orm::DbErr> { @@ -15,10 +15,22 @@ pub async fn update_users(ctx: upub::Context, days: i64, limit: Option) -> if let Some(limit) = limit { if count >= limit { break } } - match ctx.pull(&user.id).await.map(|x| x.actor()) { - Err(e) => tracing::warn!("could not update user {}: {e}", user.id), - Ok(Err(e)) => tracing::warn!("could not update user {}: {e}", user.id), - Ok(Ok(doc)) => match upub::AP::actor_q(&doc, Some(user.internal)) { + match ctx.pull(&user.id).await.and_then(|x| x.actor()) { + Err(upub::traits::fetch::RequestError::Fetch(status, msg)) => { + if status.as_u16() == 410 { + tracing::info!("user {} has been deleted", user.id); + user.delete(ctx.db()).await?; + } + else if status.as_u16() == 404 { + tracing::info!("user {} does not exist anymore", user.id); + user.delete(ctx.db()).await?; + } + else { + tracing::warn!("could not fetch user {}: failed with status {status} -- {msg}", user.id); + } + }, + Err(e) => tracing::warn!("could not fetch user {}: {e}", user.id), + Ok(doc) => match upub::AP::actor_q(&doc, Some(user.internal)) { Ok(mut u) => { tracing::info!("updating user {}", user.id); u.updated = Set(chrono::Utc::now());