Dont retry activity send in case of connection error or HTTP status 4xx (#8)
This commit is contained in:
parent
5d670513d6
commit
f9de5c1b10
1 changed files with 33 additions and 23 deletions
|
@ -22,7 +22,7 @@ use itertools::Itertools;
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Debug, future::Future, pin::Pin, time::Duration};
|
use std::{fmt::Debug, future::Future, pin::Pin, time::Duration};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, log::debug, warn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// Send out the given activity to all inboxes, automatically generating the HTTP signatures. By
|
/// Send out the given activity to all inboxes, automatically generating the HTTP signatures. By
|
||||||
|
@ -130,7 +130,7 @@ async fn do_send(
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
info!("Sending {} to {}", task.activity_id, task.inbox);
|
debug!("Sending {} to {}", task.activity_id, task.inbox);
|
||||||
let request_builder = client
|
let request_builder = client
|
||||||
.post(&task.inbox.to_string())
|
.post(&task.inbox.to_string())
|
||||||
.timeout(timeout)
|
.timeout(timeout)
|
||||||
|
@ -146,28 +146,38 @@ async fn do_send(
|
||||||
let response = client.execute(request).await;
|
let response = client.execute(request).await;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(o) => {
|
Ok(o) if o.status().is_success() => {
|
||||||
if o.status().is_success() {
|
info!(
|
||||||
Ok(())
|
"Activity {} delivered successfully to {}",
|
||||||
} else {
|
task.activity_id, task.inbox
|
||||||
let status = o.status();
|
);
|
||||||
let text = o.text().await.map_err(Error::conv)?;
|
Ok(())
|
||||||
|
}
|
||||||
Err(anyhow!(
|
Ok(o) if o.status().is_client_error() => {
|
||||||
"Send {} to {} failed with status {}: {}",
|
info!(
|
||||||
task.activity_id,
|
"Target server {} rejected {}, aborting",
|
||||||
task.inbox,
|
task.inbox, task.activity_id,
|
||||||
status,
|
);
|
||||||
text,
|
Ok(())
|
||||||
))
|
}
|
||||||
}
|
Ok(o) => {
|
||||||
|
let status = o.status();
|
||||||
|
let text = o.text().await.map_err(Error::conv)?;
|
||||||
|
Err(anyhow!(
|
||||||
|
"Queueing activity {} to {} for retry after failure with status {}: {}",
|
||||||
|
task.activity_id,
|
||||||
|
task.inbox,
|
||||||
|
status,
|
||||||
|
text,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
info!(
|
||||||
|
"Unable to connect to {}, aborting task {}: {}",
|
||||||
|
task.inbox, task.activity_id, e
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => Err(anyhow!(
|
|
||||||
"Failed to send activity {} to {}: {}",
|
|
||||||
&task.activity_id,
|
|
||||||
task.inbox,
|
|
||||||
e
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue