pipedash_plugin_api/logs/
fetch.rs1use std::time::Duration;
2
3use reqwest::header::RANGE;
4use reqwest::{
5 RequestBuilder,
6 Response,
7 Url,
8};
9
10use crate::error::{
11 PluginError,
12 PluginResult,
13};
14use crate::utils::RetryPolicy;
15
16pub const LOG_REQUEST_TIMEOUT: Duration = Duration::from_secs(900);
17
18pub async fn send_log(
19 retry: &RetryPolicy, url: &Url, from: Option<u64>, gone: &str,
20 build: impl Fn() -> RequestBuilder,
21) -> PluginResult<Response> {
22 let response = retry
23 .retry_unsent(url, || {
24 let request = build().timeout(LOG_REQUEST_TIMEOUT);
25 match from {
26 Some(from) => request.header(RANGE, format!("bytes={from}-")),
27 None => request,
28 }
29 .send()
30 })
31 .await?;
32
33 if matches!(response.status().as_u16(), 404 | 410) {
34 return Err(PluginError::PipelineNotFound(gone.to_string()));
35 }
36 Ok(response)
37}
38
39#[cfg(test)]
40mod tests;