MCPcopy Create free account
hub / github.com/Firstyear/opensuse-proxy-cache / prefetch_dl_task

Function prefetch_dl_task

opensuse-proxy-cache/src/main.rs:1122–1172  ·  view source on GitHub ↗
(
    client: reqwest::Client,
    fetch_url: Url,
    submit_tx: Sender<CacheMeta>,
    cache_key: PathBuf,
    tmp_file: NamedTempFile,
    cls: Classification,
)

Source from the content-addressed store, hash-verified

1120
1121#[instrument(skip_all)]
1122async fn prefetch_dl_task(
1123 client: reqwest::Client,
1124 fetch_url: Url,
1125 submit_tx: Sender<CacheMeta>,
1126 cache_key: PathBuf,
1127 tmp_file: NamedTempFile,
1128 cls: Classification,
1129) {
1130 info!("🚅 start prefetch {}", cache_key.display());
1131
1132 let send_headers = send_headers(None);
1133
1134 let client_response = client.get(fetch_url).headers(send_headers).send().await;
1135
1136 let client_response = match client_response {
1137 Ok(cr) => cr,
1138 Err(e) => {
1139 error!(?e, "Error handling client response");
1140 return;
1141 }
1142 };
1143
1144 let status = client_response.status();
1145 if status == StatusCode::NOT_FOUND {
1146 info!("👻 prefetch rewrite -> NotFound");
1147 let etime = time::OffsetDateTime::now_utc();
1148 let _ = submit_tx
1149 .send(CacheMeta {
1150 cache_key,
1151 etime,
1152 action: Action::NotFound { cls },
1153 })
1154 .await;
1155 return;
1156 } else if status != StatusCode::OK {
1157 error!("Response returned {:?}, aborting prefetch", status);
1158 return;
1159 }
1160
1161 let headers = filter_headers(client_response.headers(), false);
1162
1163 let byte_reader = StreamReader::new(
1164 client_response
1165 .bytes_stream()
1166 .map(|item| item.map_err(|e| std::io::Error::other(e))),
1167 );
1168
1169 let _ = tokio::task::spawn(async move {
1170 write_file(cache_key, headers, tmp_file, submit_tx, cls, byte_reader).await
1171 });
1172}
1173
1174#[instrument(skip_all)]
1175async fn found(

Callers

nothing calls this directly

Calls 4

send_headersFunction · 0.85
filter_headersFunction · 0.85
write_fileFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected