Skip to content

Commit

Permalink
Update Race Condition in tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-zip committed Oct 7, 2023
1 parent 5dec915 commit af63fbe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
8 changes: 4 additions & 4 deletions maid_reports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
warp = "0.2"
parking_lot = "0.10.0"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "0.2", features = ["macros"] }
parking_lot = "0.12.1"
serde = "1.0.188"
serde_json = "1.0.107"
tokio = "1.32.0"
warp = "0.3.6"
39 changes: 27 additions & 12 deletions maid_reports/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
mod meow;
mod api;
mod meow;

use crate::api::api::*;
use warp::Filter;

#[tokio::main]
async fn main() {
// Define a filter that matches a GET request to the /jsonl endpoint.
let jsonl_route = warp::path!("jsonl")
.and(warp::get())
.map(|| {
// Read the JSONL file and return it as a response.
let file_content = read_jsonl_file();
warp::reply::with_header(file_content, warp::http::header::CONTENT_TYPE, "application/json")
});
// Replace "your_jsonl_file.jsonl" with the path to your JSONL file.
let config = read_meow("/var/maid/maid_lists/embedded/config.meow", false);
let file_path = format!("{}{}", config["REPORT_BASE_PATH"], config["REPORT_LOG"]);

let jsonl_route = warp::path!("jsonl").and(warp::get()).map(|| {
// Read the JSONL file and return it as a response.
let file_content = read_file(file_path);
warp::reply::with_header(
file_content,
warp::http::header::CONTENT_TYPE,
"application/json",
)
});


let index_page = config["INDEX"].to_string();
let index = warp::path!("/").and(warp::get()).map(|| {
let file_content = read_file(index_page);
warp::reply::with_header(
file_content,
warp::http::header::CONTENT_TYPE,
"text/html",
)
});

// Start the Warp server.
warp::serve(jsonl_route)
.run(([127, 0, 0, 1], 3030))
.await;
}
warp::serve(jsonl_route, index).run(([127, 0, 0, 1], 8000)).await;
}

0 comments on commit af63fbe

Please sign in to comment.