Set up a global maps (cache) object
This commit is contained in:
parent
b5dae45868
commit
d058ab4448
|
@ -1599,6 +1599,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"color-eyre",
|
||||
"geocoding",
|
||||
"once_cell",
|
||||
"rocket",
|
||||
]
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ edition = "2021"
|
|||
chrono = "0.4.19"
|
||||
color-eyre = "0.5.6"
|
||||
geocoding = "0.3.1"
|
||||
once_cell = "1.9.0"
|
||||
rocket = { version = "0.5.0-rc.1", features = ["json"] }
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
|
||||
use color_eyre::Result;
|
||||
use geocoding::{Forward, Openstreetmap, Point};
|
||||
use once_cell::sync::Lazy;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::serde::Serialize;
|
||||
use rocket::tokio::sync::Mutex;
|
||||
use rocket::tokio::{self, select};
|
||||
use rocket::{get, routes, FromFormField};
|
||||
|
||||
|
@ -22,6 +24,8 @@ use self::maps::Maps;
|
|||
|
||||
mod maps;
|
||||
|
||||
static MAPS: Lazy<Mutex<Maps>> = Lazy::new(|| Mutex::new(Maps::default()));
|
||||
|
||||
/// The current for a specific location.
|
||||
///
|
||||
/// Only the metrics asked for are included as well as the position and current time.
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use rocket::tokio::time::{sleep, Duration};
|
||||
|
||||
use crate::MAPS;
|
||||
|
||||
/// The interval between map refreshes (in seconds).
|
||||
const SLEEP_INTERVAL: u64 = 60;
|
||||
|
||||
|
@ -11,6 +13,8 @@ pub(crate) struct Maps;
|
|||
impl Maps {
|
||||
pub(crate) async fn run() -> ! {
|
||||
loop {
|
||||
let _maps = MAPS.lock().await;
|
||||
|
||||
sleep(Duration::from_secs(SLEEP_INTERVAL)).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue