Skip to content

Commit

Permalink
fixed formatting mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Feb 27, 2024
1 parent 7647a82 commit 69d2503
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions server/main-api/src/maps/fetch_tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::time::Duration;
use cached::proc_macro::io_cached;
use log::{error, warn};

use crate::BoxedError;
use crate::maps::overlay_map::OverlayMapTask;
use crate::BoxedError;

#[derive(Hash, Debug, Copy, Clone)]
struct TileLocation {
Expand All @@ -25,7 +25,6 @@ impl Display for TileLocation {
}
}


#[derive(Debug)]
pub(crate) struct FetchTileTask {
location: TileLocation,
Expand Down Expand Up @@ -91,7 +90,6 @@ impl FetchTileTask {
}
}


// type and create are specified, because a custom conversion is needed
pub async fn fulfill(self) -> Option<((u32, u32), image::DynamicImage)> {
let raw_tile = download_map_image(self.location).await;
Expand All @@ -102,7 +100,7 @@ impl FetchTileTask {
error!("Error while parsing image: {e:#?} for {self:?}");
None
}
}
},
Err(e) => {
error!("could not fulfill {self:?} because {e}");
None
Expand All @@ -113,7 +111,12 @@ impl FetchTileTask {

#[io_cached(disk = true, map_error = r##"|e| format!("{e:?}")"##)]
async fn download_map_image(location: TileLocation) -> Result<Vec<u8>, BoxedError> {
let url = format!("https://nav.tum.de/maps/styles/osm-liberty/{z}/{x}/{y}@2x.png", x = location.x, y = location.y, z = location.z);
let url = format!(
"https://nav.tum.de/maps/styles/osm-liberty/{z}/{x}/{y}@2x.png",
x = location.x,
y = location.y,
z = location.z
);
for i in 1..5 {
let res = reqwest::get(&url).await?.bytes().await?;
// wait with exponential backoff
Expand All @@ -122,9 +125,12 @@ async fn download_map_image(location: TileLocation) -> Result<Vec<u8>, BoxedErro
} else {
let wait_time_ms = 1.5_f32.powi(i).round() as u64;
let wait_time = Duration::from_millis(wait_time_ms);
warn!("retrying tileserver-request in {wait_time:?} because it is only {request_len}B", request_len=res.len());
warn!(
"retrying tileserver-request in {wait_time:?} because it is only {request_len}B",
request_len = res.len()
);
tokio::time::sleep(wait_time).await;
}
};
}
Err(format!("Got only short Responses from {url}").into())
}
}

0 comments on commit 69d2503

Please sign in to comment.