send activities sync for tests
This commit is contained in:
parent
a455e8c0ab
commit
f33577b317
4 changed files with 38 additions and 24 deletions
|
@ -8,6 +8,7 @@ export LEMMY_SETUP__ADMIN_PASSWORD=lemmy
|
||||||
export LEMMY_RATE_LIMIT__POST=99999
|
export LEMMY_RATE_LIMIT__POST=99999
|
||||||
export LEMMY_RATE_LIMIT__REGISTER=99999
|
export LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
export LEMMY_CAPTCHA__ENABLED=false
|
export LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
export LEMMY_TEST_SEND_SYNC=1
|
||||||
export RUST_BACKTRACE=1
|
export RUST_BACKTRACE=1
|
||||||
|
|
||||||
for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
|
for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
|
||||||
|
|
|
@ -615,7 +615,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
|
||||||
|
|
||||||
export function delay(millis: number = 500) {
|
export function delay(millis: number = 500) {
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
setTimeout(_ => resolve(), millis);
|
setTimeout(_ => resolve(), 10);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ services:
|
||||||
- LEMMY_RATE_LIMIT__POST=99999
|
- LEMMY_RATE_LIMIT__POST=99999
|
||||||
- LEMMY_RATE_LIMIT__REGISTER=99999
|
- LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
- LEMMY_CAPTCHA__ENABLED=false
|
- LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
- LEMMY_TEST_SEND_SYNC=1
|
||||||
- RUST_BACKTRACE=1
|
- RUST_BACKTRACE=1
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@ -91,6 +92,7 @@ services:
|
||||||
- LEMMY_RATE_LIMIT__POST=99999
|
- LEMMY_RATE_LIMIT__POST=99999
|
||||||
- LEMMY_RATE_LIMIT__REGISTER=99999
|
- LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
- LEMMY_CAPTCHA__ENABLED=false
|
- LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
- LEMMY_TEST_SEND_SYNC=1
|
||||||
- RUST_BACKTRACE=1
|
- RUST_BACKTRACE=1
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@ -130,6 +132,7 @@ services:
|
||||||
- LEMMY_RATE_LIMIT__POST=99999
|
- LEMMY_RATE_LIMIT__POST=99999
|
||||||
- LEMMY_RATE_LIMIT__REGISTER=99999
|
- LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
- LEMMY_CAPTCHA__ENABLED=false
|
- LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
- LEMMY_TEST_SEND_SYNC=1
|
||||||
- RUST_BACKTRACE=1
|
- RUST_BACKTRACE=1
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@ -170,6 +173,7 @@ services:
|
||||||
- LEMMY_RATE_LIMIT__POST=99999
|
- LEMMY_RATE_LIMIT__POST=99999
|
||||||
- LEMMY_RATE_LIMIT__REGISTER=99999
|
- LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
- LEMMY_CAPTCHA__ENABLED=false
|
- LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
- LEMMY_TEST_SEND_SYNC=1
|
||||||
- RUST_BACKTRACE=1
|
- RUST_BACKTRACE=1
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
depends_on:
|
depends_on:
|
||||||
|
@ -210,6 +214,7 @@ services:
|
||||||
- LEMMY_RATE_LIMIT__POST=99999
|
- LEMMY_RATE_LIMIT__POST=99999
|
||||||
- LEMMY_RATE_LIMIT__REGISTER=99999
|
- LEMMY_RATE_LIMIT__REGISTER=99999
|
||||||
- LEMMY_CAPTCHA__ENABLED=false
|
- LEMMY_CAPTCHA__ENABLED=false
|
||||||
|
- LEMMY_TEST_SEND_SYNC=1
|
||||||
- RUST_BACKTRACE=1
|
- RUST_BACKTRACE=1
|
||||||
- RUST_LOG=debug
|
- RUST_LOG=debug
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
|
@ -25,7 +25,7 @@ use lemmy_websocket::LemmyContext;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{export::fmt::Debug, Deserialize, Serialize};
|
use serde::{export::fmt::Debug, Deserialize, Serialize};
|
||||||
use std::{collections::BTreeMap, future::Future, pin::Pin};
|
use std::{collections::BTreeMap, future::Future, pin::Pin, env};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// Sends a local activity to a single, remote actor.
|
/// Sends a local activity to a single, remote actor.
|
||||||
|
@ -234,8 +234,12 @@ where
|
||||||
actor_id: actor.actor_id()?,
|
actor_id: actor.actor_id()?,
|
||||||
private_key: actor.private_key().context(location_info!())?,
|
private_key: actor.private_key().context(location_info!())?,
|
||||||
};
|
};
|
||||||
|
if env::var("LEMMY_TEST_SEND_SYNC").is_ok() {
|
||||||
|
do_send(message, &Client::default()).await?;
|
||||||
|
} else {
|
||||||
activity_sender.queue::<SendActivityTask>(message)?;
|
activity_sender.queue::<SendActivityTask>(message)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -260,15 +264,21 @@ impl ActixJob for SendActivityTask {
|
||||||
|
|
||||||
fn run(self, state: Self::State) -> Self::Future {
|
fn run(self, state: Self::State) -> Self::Future {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
do_send(self, &state.client).await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn do_send(task: SendActivityTask, client: &Client) -> Result<(), Error>{
|
||||||
let mut headers = BTreeMap::<String, String>::new();
|
let mut headers = BTreeMap::<String, String>::new();
|
||||||
headers.insert("Content-Type".into(), "application/json".into());
|
headers.insert("Content-Type".into(), "application/json".into());
|
||||||
let result = sign_and_send(
|
let result = sign_and_send(
|
||||||
&state.client,
|
client,
|
||||||
headers,
|
headers,
|
||||||
&self.inbox,
|
&task.inbox,
|
||||||
self.activity.clone(),
|
task.activity.clone(),
|
||||||
&self.actor_id,
|
&task.actor_id,
|
||||||
self.private_key.to_owned(),
|
task.private_key.to_owned(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -276,13 +286,11 @@ impl ActixJob for SendActivityTask {
|
||||||
warn!("{}", e);
|
warn!("{}", e);
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"Failed to send activity {} to {}",
|
"Failed to send activity {} to {}",
|
||||||
&self.activity,
|
&task.activity,
|
||||||
self.inbox
|
task.inbox
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_activity_queue() -> QueueHandle {
|
pub fn create_activity_queue() -> QueueHandle {
|
||||||
|
|
Loading…
Reference in a new issue