Skip to content

Commit

Permalink
feat: Add quota info to __heartbeat__ (#948)
Browse files Browse the repository at this point in the history
* feat: Add quota info to __heartbeat__

Closes #947
  • Loading branch information
jrconlin authored Dec 5, 2020
1 parent d6e6c2c commit 19ce36b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/web/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,17 @@ impl FromRequest for BsoPutRequest {
}
}

#[derive(Clone, Copy, Debug, Serialize)]
pub struct QuotaInfo {
pub enabled: bool,
pub size: u32,
}

#[derive(Clone, Debug)]
pub struct HeartbeatRequest {
pub headers: HeaderMap,
pub db_pool: Box<dyn DbPool>,
pub quota: QuotaInfo,
}

impl FromRequest for HeartbeatRequest {
Expand All @@ -918,7 +925,16 @@ impl FromRequest for HeartbeatRequest {
}
};
let db_pool = state.db_pool.clone();
Ok(HeartbeatRequest { headers, db_pool })
let quota = QuotaInfo {
enabled: state.quota_enabled,
size: state.limits.max_quota_limit,
};

Ok(HeartbeatRequest {
headers,
db_pool,
quota,
})
}
.boxed_local()
}
Expand Down
2 changes: 2 additions & 0 deletions src/web/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ pub async fn heartbeat(hb: HeartbeatRequest) -> Result<HttpResponse, Error> {
);
let db = hb.db_pool.get().await?;

checklist.insert("quota".to_owned(), serde_json::to_value(hb.quota)?);

match db.check().await {
Ok(result) => {
if result {
Expand Down

0 comments on commit 19ce36b

Please sign in to comment.