mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
Run HTTP request in broadcast() on tokio runtime
This commit is contained in:
parent
e0258003b9
commit
a7b899817a
1 changed files with 48 additions and 40 deletions
|
@ -1,12 +1,13 @@
|
|||
use activitypub::{Activity, Link, Object};
|
||||
use array_tool::vec::Uniq;
|
||||
use reqwest::{blocking::ClientBuilder, header::HeaderValue, Url};
|
||||
use reqwest::{header::HeaderValue, ClientBuilder, Url};
|
||||
use rocket::{
|
||||
http::Status,
|
||||
request::{FromRequest, Request},
|
||||
response::{Responder, Response},
|
||||
Outcome,
|
||||
};
|
||||
use tokio::runtime;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use self::sign::Signable;
|
||||
|
@ -139,6 +140,11 @@ where
|
|||
.connect_timeout(std::time::Duration::from_secs(5))
|
||||
.build()
|
||||
.expect("Can't build client");
|
||||
let rt = runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("Error while initializing tokio runtime for federation");
|
||||
rt.block_on(async {
|
||||
for inbox in boxes {
|
||||
let body = signed.to_string();
|
||||
let mut headers = request::headers();
|
||||
|
@ -169,6 +175,7 @@ where
|
|||
)
|
||||
.body(body)
|
||||
.send()
|
||||
.await
|
||||
.map(move |r| {
|
||||
if r.status().is_success() {
|
||||
debug!("Successfully sent activity to inbox ({})", &inbox);
|
||||
|
@ -179,6 +186,7 @@ where
|
|||
})
|
||||
.map_err(|e| warn!("Error while sending to inbox ({:?})", e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Shrinkwrap, Clone, Serialize, Deserialize)]
|
||||
|
|
Loading…
Reference in a new issue