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,19 +101,36 @@ 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);
let mut retry_count = 0;
let max_retries = 2;
while !inboxes.is_empty() && retry_count <= max_retries {
if retry_count > 0 {
// Wait 30 secs before next attempt
sleep(Duration::from_secs(30)).await;
};
let mut failed = vec![];
for inbox_url in inboxes { for inbox_url in inboxes {
// TODO: retry on error if let Err(error) = send_activity(
if let Err(err) = send_activity(
&instance, &instance,
&actor_key, &actor_key,
&actor_key_id, &actor_key_id,
&activity_json, &activity_json,
&inbox_url, &inbox_url,
).await { ).await {
log::error!("failed to deliver activity to {}: {}", inbox_url, err); 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(())
} }