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;
|
2023-07-19 10:09:04 +00:00
|
|
|
pub mod cache_header;
|
2020-09-14 15:29:50 +00:00
|
|
|
pub mod email;
|
2022-06-02 14:33:41 +00:00
|
|
|
pub mod error;
|
2023-10-09 10:46:12 +00:00
|
|
|
pub mod rate_limit;
|
2022-05-03 17:44:13 +00:00
|
|
|
pub mod request;
|
2023-07-10 20:44:14 +00:00
|
|
|
pub mod response;
|
2023-10-09 10:46:12 +00:00
|
|
|
pub mod settings;
|
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;
|
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
|
|
|
|
|
|
|
/// 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
|
|
|
|
);
|
|
|
|
}
|