lemmy/crates/utils/src/lib.rs
Nutomic 1d0a6ac08f
Avoid breaking api change, reduce api cache duration (#4610)
* Dont mark site.public_key as `serde(skip)` to avoid breaking change (fixes #4605)

* Reduce cache duration for api
2024-04-09 10:10:20 -04:00

61 lines
1.4 KiB
Rust

use cfg_if::cfg_if;
cfg_if! {
if #[cfg(feature = "full")] {
pub mod apub;
pub mod cache_header;
pub mod email;
pub mod rate_limit;
pub mod request;
pub mod response;
pub mod settings;
pub mod utils;
}
}
pub mod error;
pub use error::LemmyErrorType;
use std::time::Duration;
pub type ConnectionId = usize;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
#[cfg(debug_assertions)]
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_millis(500);
#[cfg(not(debug_assertions))]
pub const CACHE_DURATION_FEDERATION: Duration = Duration::from_secs(60);
pub const CACHE_DURATION_API: Duration = Duration::from_secs(1);
#[macro_export]
macro_rules! location_info {
() => {
format!(
"None value at {}:{}, column {}",
file!(),
line!(),
column!()
)
};
}
#[cfg(feature = "full")]
/// 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 futures::Future<Output = Result<(), error::LemmyError>> + Send + 'static,
) {
use tracing::Instrument;
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
);
}