2024-02-25 00:54:27 +00:00
|
|
|
use cfg_if::cfg_if;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2024-02-25 00:54:27 +00:00
|
|
|
cfg_if! {
|
2024-02-27 16:13:52 +00:00
|
|
|
if #[cfg(feature = "full")] {
|
2024-02-25 00:54:27 +00:00
|
|
|
pub mod cache_header;
|
|
|
|
pub mod email;
|
|
|
|
pub mod rate_limit;
|
|
|
|
pub mod request;
|
|
|
|
pub mod response;
|
|
|
|
pub mod settings;
|
|
|
|
pub mod utils;
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2024-02-27 16:13:52 +00:00
|
|
|
pub mod error;
|
|
|
|
pub use error::LemmyErrorType;
|
2023-06-21 08:28:20 +00:00
|
|
|
use std::time::Duration;
|
2020-09-01 14:25:34 +00:00
|
|
|
|
|
|
|
pub type ConnectionId = usize;
|
2021-03-18 20:25:21 +00:00
|
|
|
|
2024-04-02 15:19:51 +00:00
|
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
|
2022-03-24 16:33:23 +00:00
|
|
|
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
|
|
2024-04-03 21:38:31 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2024-04-09 14:10:20 +00:00
|
|
|
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_millis(500);
|
2024-04-03 21:38:31 +00:00
|
|
|
#[cfg(not(debug_assertions))]
|
2024-04-09 14:10:20 +00:00
|
|
|
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_secs(60);
|
|
|
|
|
|
|
|
pub const CACHE_DURATION_API: Duration = Duration::from_secs(1);
|
2024-04-03 21:38:31 +00:00
|
|
|
|
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
|
|
|
|
2024-02-27 16:13:52 +00:00
|
|
|
#[cfg(feature = "full")]
|
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
|
2024-02-25 00:54:27 +00:00
|
|
|
pub fn spawn_try_task(
|
|
|
|
task: impl futures::Future<Output = Result<(), error::LemmyError>> + Send + 'static,
|
|
|
|
) {
|
|
|
|
use tracing::Instrument;
|
2023-07-10 10:27:49 +00:00
|
|
|
tokio::spawn(
|
|
|
|
async {
|
|
|
|
if let Err(e) = task.await {
|
|
|
|
tracing::warn!("error in spawn: {e}");
|
|
|
|
}
|
|
|
|
}
|
2024-05-23 12:46:26 +00:00
|
|
|
.in_current_span(), /* this makes sure the inner tracing gets the same context as where
|
|
|
|
* spawn was called */
|
2023-07-10 10:27:49 +00:00
|
|
|
);
|
|
|
|
}
|