2 extern crate strum_macros;
4 extern crate smart_default;
18 use error::LemmyError;
20 use once_cell::sync::Lazy;
21 use std::time::Duration;
22 use tracing::Instrument;
24 pub type ConnectionId = usize;
26 pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
29 macro_rules! location_info {
32 "None value at {}:{}, column {}",
40 /// if true, all federation should happen synchronously. useful for debugging and testing.
41 /// defaults to true on debug mode, false on releasemode
42 /// override to true by setting env LEMMY_SYNCHRONOUS_FEDERATION=1
43 /// override to false by setting env LEMMY_SYNCHRONOUS_FEDERATION=""
44 pub static SYNCHRONOUS_FEDERATION: Lazy<bool> = Lazy::new(|| {
45 std::env::var("LEMMY_SYNCHRONOUS_FEDERATION")
46 .map(|s| !s.is_empty())
47 .unwrap_or(cfg!(debug_assertions))
50 /// tokio::spawn, but accepts a future that may fail and also
52 /// * attaches the spawned task to the tracing span of the caller for better logging
53 pub fn spawn_try_task(task: impl Future<Output = Result<(), LemmyError>> + Send + 'static) {
56 if let Err(e) = task.await {
57 tracing::warn!("error in spawn: {e}");
60 .in_current_span(), // this makes sure the inner tracing gets the same context as where spawn was called