Skip to content

Commit

Permalink
Add status API
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Jun 1, 2024
1 parent 0dd3907 commit fbd4426
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions daemon/src/api/indexing_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;

pub(super) async fn indexing_status(index: DocumentIndex) -> Result<impl warp::Reply, Infallible> {
let status = index.status().await;
let status_json = match serde_json::to_string(&status) {
Ok(json) => json,
Err(e) => {
error!("Failed to serialize indexing status: {}", e);
return Ok(Response::builder().status(500).body("Failed to serialize indexing status".to_string()).unwrap());
}
};
Ok(Response::builder().header("Content-Type", "application/json").body(status_json).unwrap())
}
12 changes: 11 additions & 1 deletion daemon/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use warp::{Filter, http::Response};
use std::{convert::Infallible, net::SocketAddr};

mod bodies;
mod indexing_status;
mod local_search;
mod search;
mod results;
mod version;
use {
local_search::*,
bodies::*,
indexing_status::*,
local_search::*,
search::*,
results::*,
version::*,
Expand Down Expand Up @@ -60,6 +62,7 @@ impl SearchPark {
id
}

#[allow(clippy::map_clone)]
pub async fn get_query(self: Arc<Self>, id: usize) -> Option<Arc<Query>> {
let searches = self.searches.read().await;
searches.get(&id).map(|s| Arc::clone(&s.query))
Expand All @@ -76,6 +79,12 @@ impl SearchPark {
pub async fn serve_api(config: Arc<Args>, index: DocumentIndex, search_park: Arc<SearchPark>, kamilata: NodeController) {
let hello_world = warp::path::end().map(|| "Hello, World at root!");

let index2 = index.clone();
let indexing_status = warp::get()
.and(warp::path("indexing-status"))
.map(move || index2.clone())
.and_then(indexing_status);

let local_search = warp::get()
.and(warp::path("local-search"))
.and(warp::query::<ApiSearchQuery>())
Expand Down Expand Up @@ -125,6 +134,7 @@ pub async fn serve_api(config: Arc<Args>, index: DocumentIndex, search_park: Arc

let routes = warp::any().and(
hello_world
.or(indexing_status)
.or(local_search)
.or(search)
.or(results)
Expand Down

0 comments on commit fbd4426

Please sign in to comment.