Skip to content

Commit b468e85

Browse files
committed
add last update to stats
1 parent a357020 commit b468e85

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

datafeed-cache-server/src/api/handlers.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use crate::api::helper;
12
use crate::api::state::ApiStateData;
23
use actix_web::HttpResponse;
3-
use chrono::Utc;
4+
use chrono::{DateTime, Utc};
45
use datafeed_cache_shared::datafeed::{
56
DatafeedAtis, DatafeedController, DatafeedMilitaryRating, DatafeedPilot, DatafeedPilotRating,
67
DatafeedServer,
@@ -11,7 +12,6 @@ use datafeed_cache_shared::response::{
1112
use serde::Serialize;
1213
use std::borrow::Cow;
1314
use std::ops::Deref;
14-
use crate::api::helper;
1515

1616
#[actix_web::get("")]
1717
async fn get_datafeed(data: ApiStateData) -> HttpResponse {
@@ -202,6 +202,7 @@ async fn get_stats(data: ApiStateData) -> HttpResponse {
202202
len_pilots_ger: usize,
203203
len_controllers_ger: usize,
204204
failed: bool,
205+
last_update: Option<DateTime<Utc>>,
205206
}
206207

207208
let read_lock = data.shared_state.read().await;
@@ -211,9 +212,7 @@ async fn get_stats(data: ApiStateData) -> HttpResponse {
211212
let ger_controllers = helper::get_ger_controllers(&status.data);
212213

213214
let (len_pilots, len_controllers) = match &status.data {
214-
Some(df) => {
215-
(df.pilots.len(), df.controllers.len())
216-
},
215+
Some(df) => (df.pilots.len(), df.controllers.len()),
217216
None => (0, 0),
218217
};
219218

@@ -223,6 +222,10 @@ async fn get_stats(data: ApiStateData) -> HttpResponse {
223222
len_pilots_ger: ger_pilots.len(),
224223
len_controllers_ger: ger_controllers.len(),
225224
failed: status.failed,
225+
last_update: match status.data {
226+
Some(df) => Some(df.general.update_timestamp),
227+
None => None,
228+
},
226229
})
227230
}
228231

datafeed-cache-shared/src/response.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::datafeed::{Datafeed, DatafeedGeneral};
2+
use chrono::{DateTime, Utc};
23
use serde::{Deserialize, Serialize};
34
use std::borrow::Cow;
45

@@ -38,11 +39,11 @@ where
3839
}
3940

4041
#[derive(Serialize, Deserialize, Debug)]
41-
pub struct DatafeedGerStatsResponse
42-
{
42+
pub struct DatafeedGerStatsResponse {
4343
pub len_pilots: usize,
4444
pub len_controllers: usize,
4545
pub len_pilots_ger: usize,
4646
pub len_controllers_ger: usize,
4747
pub failed: bool,
48-
}
48+
last_update: Option<DateTime<Utc>>,
49+
}

0 commit comments

Comments
 (0)