(
client: reqwest::Client,
prefetch_tx: Sender<PrefetchReq>,
fetch_url: Url,
submit_tx: Sender<CacheMeta>,
tmp_file: NamedTempFile,
obj: CacheObj<PathBuf, Status>,
prefetch
| 363 | |
| 364 | #[instrument(skip_all)] |
| 365 | async fn async_refresh_task( |
| 366 | client: reqwest::Client, |
| 367 | prefetch_tx: Sender<PrefetchReq>, |
| 368 | fetch_url: Url, |
| 369 | submit_tx: Sender<CacheMeta>, |
| 370 | tmp_file: NamedTempFile, |
| 371 | obj: CacheObj<PathBuf, Status>, |
| 372 | prefetch_paths: Option<Vec<PrefetchItem>>, |
| 373 | ) { |
| 374 | info!( |
| 375 | "🥺 start async refresh {}", |
| 376 | obj.userdata.cache_key.display() |
| 377 | ); |
| 378 | |
| 379 | if !refresh(&client, fetch_url.clone(), &obj).await { |
| 380 | info!( |
| 381 | "🥰 async prefetch, content still valid {}", |
| 382 | obj.userdata.cache_key.display() |
| 383 | ); |
| 384 | let etime = time::OffsetDateTime::now_utc(); |
| 385 | // If we can't submit, we are probably shutting down so just finish up cleanly. |
| 386 | // That's why we ignore these errors. |
| 387 | // |
| 388 | // If this item is valid we can update all the related prefetch items. |
| 389 | let _ = submit_tx |
| 390 | .send(CacheMeta { |
| 391 | cache_key: obj.userdata.cache_key.clone(), |
| 392 | etime, |
| 393 | action: Action::Update, |
| 394 | }) |
| 395 | .await; |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | info!( |
| 400 | "😵 async refresh, need to refresh {}", |
| 401 | obj.userdata.cache_key.display() |
| 402 | ); |
| 403 | |
| 404 | prefetch(prefetch_tx.clone(), &submit_tx, prefetch_paths); |
| 405 | |
| 406 | // Fetch our actual file too |
| 407 | |
| 408 | if prefetch_tx |
| 409 | .send(PrefetchReq { |
| 410 | cache_key: obj.userdata.cache_key.clone(), |
| 411 | fetch_url, |
| 412 | submit_tx: submit_tx, |
| 413 | tmp_file, |
| 414 | cls: obj.userdata.cls, |
| 415 | }) |
| 416 | .await |
| 417 | .is_err() |
| 418 | { |
| 419 | error!("Prefetch task may have died!"); |
| 420 | } else { |
| 421 | debug!("Prefetch submitted"); |
| 422 | } |
no test coverage detected