2020-07-10 18:15:41 +00:00
|
|
|
#[macro_use]
|
2020-12-21 23:27:42 +00:00
|
|
|
extern crate strum_macros;
|
2021-08-04 21:13:51 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate smart_default;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2020-09-14 15:29:50 +00:00
|
|
|
pub mod apub;
|
|
|
|
pub mod email;
|
2020-12-21 23:27:42 +00:00
|
|
|
pub mod rate_limit;
|
2020-07-10 18:15:41 +00:00
|
|
|
pub mod settings;
|
2021-03-01 17:24:11 +00:00
|
|
|
|
2021-09-20 15:46:34 +00:00
|
|
|
pub mod claims;
|
2022-06-02 14:33:41 +00:00
|
|
|
pub mod error;
|
2022-05-03 17:44:13 +00:00
|
|
|
pub mod request;
|
2020-09-14 15:29:50 +00:00
|
|
|
pub mod utils;
|
2021-02-09 18:26:06 +00:00
|
|
|
pub mod version;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2023-07-10 10:27:49 +00:00
|
|
|
use error::LemmyError;
|
|
|
|
use futures::Future;
|
|
|
|
use once_cell::sync::Lazy;
|
2023-06-21 08:28:20 +00:00
|
|
|
use std::time::Duration;
|
2023-07-10 10:27:49 +00:00
|
|
|
use tracing::Instrument;
|
2020-09-01 14:25:34 +00:00
|
|
|
|
|
|
|
pub type ConnectionId = usize;
|
2021-03-18 20:25:21 +00:00
|
|
|
|
2022-03-24 16:33:23 +00:00
|
|
|
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
|
|
2020-08-11 14:31:05 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! location_info {
|
|
|
|
() => {
|
|
|
|
format!(
|
|
|
|
"None value at {}:{}, column {}",
|
|
|
|
file!(),
|
|
|
|
line!(),
|
|
|
|
column!()
|
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|
2023-07-10 10:27:49 +00:00
|
|
|
|
|
|
|
/// if true, all federation should happen synchronously. useful for debugging and testing.
|
|
|
|
/// defaults to true on debug mode, false on releasemode
|
|
|
|
/// override to true by setting env LEMMY_SYNCHRONOUS_FEDERATION=1
|
|
|
|
/// override to false by setting env LEMMY_SYNCHRONOUS_FEDERATION=""
|
|
|
|
pub static SYNCHRONOUS_FEDERATION: Lazy<bool> = Lazy::new(|| {
|
|
|
|
std::env::var("LEMMY_SYNCHRONOUS_FEDERATION")
|
|
|
|
.map(|s| !s.is_empty())
|
|
|
|
.unwrap_or(cfg!(debug_assertions))
|
|
|
|
});
|
|
|
|
|
|
|
|
/// tokio::spawn, but accepts a future that may fail and also
|
|
|
|
/// * logs errors
|
|
|
|
/// * attaches the spawned task to the tracing span of the caller for better logging
|
|
|
|
pub fn spawn_try_task(task: impl Future<Output = Result<(), LemmyError>> + Send + 'static) {
|
|
|
|
tokio::spawn(
|
|
|
|
async {
|
|
|
|
if let Err(e) = task.await {
|
|
|
|
tracing::warn!("error in spawn: {e}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.in_current_span(), // this makes sure the inner tracing gets the same context as where spawn was called
|
|
|
|
);
|
|
|
|
}
|