Retry activity delivery on failure

This commit is contained in:
silverpill 2022-07-24 21:19:17 +00:00
parent 42cbe44357
commit cef026f89a

View file

@ -1,6 +1,9 @@
use std::time::Duration;
use actix_web::http::Method; use actix_web::http::Method;
use rsa::RsaPrivateKey; use rsa::RsaPrivateKey;
use serde::Serialize; use serde::Serialize;
use tokio::time::sleep;
use crate::config::Instance; use crate::config::Instance;
use crate::http_signatures::create::{create_http_signature, SignatureError}; use crate::http_signatures::create::{create_http_signature, SignatureError};
@ -98,18 +101,35 @@ async fn deliver_activity_worker(
.collect(); .collect();
inboxes.sort(); inboxes.sort();
inboxes.dedup(); inboxes.dedup();
log::info!("sending activity to {} inboxes: {}", inboxes.len(), activity_json); log::info!("sending activity to {} inboxes: {}", inboxes.len(), activity_json);
for inbox_url in inboxes { let mut retry_count = 0;
// TODO: retry on error let max_retries = 2;
if let Err(err) = send_activity( while !inboxes.is_empty() && retry_count <= max_retries {
&instance, if retry_count > 0 {
&actor_key, // Wait 30 secs before next attempt
&actor_key_id, sleep(Duration::from_secs(30)).await;
&activity_json,
&inbox_url,
).await {
log::error!("failed to deliver activity to {}: {}", inbox_url, err);
}; };
let mut failed = vec![];
for inbox_url in inboxes {
if let Err(error) = send_activity(
&instance,
&actor_key,
&actor_key_id,
&activity_json,
&inbox_url,
).await {
log::error!(
"failed to deliver activity to {} (attempt #{}): {}",
inbox_url,
retry_count + 1,
error,
);
failed.push(inbox_url);
};
};
inboxes = failed;
retry_count += 1;
}; };
Ok(()) Ok(())
} }