My personal site cherry.computer
htmx tailwind axum askama

feat: add tracing instrumentation for media fetch functions

cherry.computer 50e36a46 33078661

verified
+9
+3
server/src/scrapers/apple_music.rs
··· 5 use reqwest::Client; 6 use serde::{Deserialize, Serialize}; 7 use tokio::sync::RwLock; 8 9 use super::{ 10 Media, ··· 121 }) 122 } 123 124 pub fn try_cached_fetch(self: Arc<Self>) -> Option<Media> { 125 try_cache_or_fetch(&self.cache.clone(), TTL, async move || self.fetch().await) 126 } 127 128 pub async fn cached_fetch(self: Arc<Self>) -> Option<Media> { 129 cache_or_fetch(&self.cache.clone(), TTL, async move || self.fetch().await).await 130 }
··· 5 use reqwest::Client; 6 use serde::{Deserialize, Serialize}; 7 use tokio::sync::RwLock; 8 + use tracing::instrument; 9 10 use super::{ 11 Media, ··· 122 }) 123 } 124 125 + #[instrument(name = "apple_music_try_cached_fetch", skip(self))] 126 pub fn try_cached_fetch(self: Arc<Self>) -> Option<Media> { 127 try_cache_or_fetch(&self.cache.clone(), TTL, async move || self.fetch().await) 128 } 129 130 + #[instrument(name = "apple_music_cached_fetch", skip(self))] 131 pub async fn cached_fetch(self: Arc<Self>) -> Option<Media> { 132 cache_or_fetch(&self.cache.clone(), TTL, async move || self.fetch().await).await 133 }
+3
server/src/scrapers/backloggd.rs
··· 7 use reqwest::Url; 8 use scraper::{Html, Selector}; 9 use tokio::sync::RwLock; 10 11 use super::{ 12 Media, ··· 80 81 static CACHE: LazyLock<MediaCache> = LazyLock::new(|| Arc::new(RwLock::new(None))); 82 static TTL: Duration = Duration::from_secs(300); 83 pub fn try_cached_fetch() -> Option<Media> { 84 try_cache_or_fetch(&CACHE, TTL, fetch) 85 } 86 pub async fn cached_fetch() -> Option<Media> { 87 cache_or_fetch(&CACHE, TTL, fetch).await 88 }
··· 7 use reqwest::Url; 8 use scraper::{Html, Selector}; 9 use tokio::sync::RwLock; 10 + use tracing::instrument; 11 12 use super::{ 13 Media, ··· 81 82 static CACHE: LazyLock<MediaCache> = LazyLock::new(|| Arc::new(RwLock::new(None))); 83 static TTL: Duration = Duration::from_secs(300); 84 + #[instrument(name = "backlogged_try_cached_fetch")] 85 pub fn try_cached_fetch() -> Option<Media> { 86 try_cache_or_fetch(&CACHE, TTL, fetch) 87 } 88 + #[instrument(name = "backlogged_cached_fetch")] 89 pub async fn cached_fetch() -> Option<Media> { 90 cache_or_fetch(&CACHE, TTL, fetch).await 91 }
+3
server/src/scrapers/letterboxd.rs
··· 8 use scraper::{ElementRef, Html, Selector}; 9 use serde::Deserialize; 10 use tokio::sync::RwLock; 11 12 use super::{ 13 Media, ··· 143 144 static CACHE: LazyLock<MediaCache> = LazyLock::new(|| Arc::new(RwLock::new(None))); 145 static TTL: Duration = Duration::from_secs(1800); 146 pub fn try_cached_fetch() -> Option<Media> { 147 try_cache_or_fetch(&CACHE, TTL, fetch) 148 } 149 pub async fn cached_fetch() -> Option<Media> { 150 cache_or_fetch(&CACHE, TTL, fetch).await 151 }
··· 8 use scraper::{ElementRef, Html, Selector}; 9 use serde::Deserialize; 10 use tokio::sync::RwLock; 11 + use tracing::instrument; 12 13 use super::{ 14 Media, ··· 144 145 static CACHE: LazyLock<MediaCache> = LazyLock::new(|| Arc::new(RwLock::new(None))); 146 static TTL: Duration = Duration::from_secs(1800); 147 + #[instrument(name = "letterboxd_try_cached_fetch")] 148 pub fn try_cached_fetch() -> Option<Media> { 149 try_cache_or_fetch(&CACHE, TTL, fetch) 150 } 151 + #[instrument(name = "letterboxd_cached_fetch")] 152 pub async fn cached_fetch() -> Option<Media> { 153 cache_or_fetch(&CACHE, TTL, fetch).await 154 }