lint and set force_write true when a request fails

federation-send-parallel
phiresky 2024-04-15 17:59:26 +02:00
parent 491daabaf2
commit 987174a6c1
2 changed files with 11 additions and 16 deletions

View File

@ -79,15 +79,7 @@ async fn start_stop_federation_workers(
let instance = instance.clone(); let instance = instance.clone();
let config = config.clone(); let config = config.clone();
let stats_sender = stats_sender.clone(); let stats_sender = stats_sender.clone();
async move { async move { InstanceWorker::init_and_loop(instance, config, stop, stats_sender).await }
InstanceWorker::init_and_loop(
instance,
config,
stop,
stats_sender,
)
.await
}
}), }),
); );
} else if !should_federate { } else if !should_federate {

View File

@ -231,7 +231,7 @@ impl InstanceWorker {
/// get newest activity id and set it as last_successful_id if it's the first time this instance is seen /// get newest activity id and set it as last_successful_id if it's the first time this instance is seen
async fn get_latest_id(&mut self) -> Result<ActivityId> { async fn get_latest_id(&mut self) -> Result<ActivityId> {
let latest_id = get_latest_activity_id(&mut self.pool()).await?; let latest_id = get_latest_activity_id(&mut self.pool()).await?;
if let None = self.state.last_successful_id { if self.state.last_successful_id.is_none() {
// this is the initial creation (instance first seen) of the federation queue for this instance // this is the initial creation (instance first seen) of the federation queue for this instance
// skip all past activities: // skip all past activities:
self.state.last_successful_id = Some(latest_id); self.state.last_successful_id = Some(latest_id);
@ -247,7 +247,7 @@ impl InstanceWorker {
successfuls: &mut BinaryHeap<SendSuccessInfo>, successfuls: &mut BinaryHeap<SendSuccessInfo>,
in_flight: &mut i64, in_flight: &mut i64,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
let force_write = false; let mut force_write = false;
let mut events = Vec::new(); let mut events = Vec::new();
// wait for at least one event but if there's multiple handle them all // wait for at least one event but if there's multiple handle them all
receive_inbox_result.recv_many(&mut events, 1000).await; receive_inbox_result.recv_many(&mut events, 1000).await;
@ -266,6 +266,7 @@ impl InstanceWorker {
// override fail count - if multiple activities are currently sending this value may get conflicting info but that's fine // override fail count - if multiple activities are currently sending this value may get conflicting info but that's fine
self.state.fail_count = fail_count; self.state.fail_count = fail_count;
self.state.last_retry = Some(Utc::now()); self.state.last_retry = Some(Utc::now());
force_write = true;
} }
} }
} }
@ -378,11 +379,13 @@ impl InstanceWorker {
ele.0.ap_id, ele.0.ap_id,
e e
); );
report.send(SendActivityResult::Success(SendSuccessInfo { report
.send(SendActivityResult::Success(SendSuccessInfo {
activity_id, activity_id,
published: None, published: None,
was_skipped: true, was_skipped: true,
})).ok(); }))
.ok();
} }
}); });
Ok(()) Ok(())