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