Skip to content

Commit

Permalink
Merge branch 'restart_auditor_webservice_stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacderida committed Oct 7, 2024
2 parents 3ce5489 + 979e03c commit b069273
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Added

- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support capping node log output
- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support
capping node log output

#### Fixed

Expand All @@ -30,7 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Increased logging related to app configuration. This could help solving issues on launchpad start up.
- Increased logging related to app configuration. This could help solving issues on launchpad start
up.

## 2024-10-03

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sn_auditor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["MaidSafe Developers <dev@maidsafe.net>"]
description = "Safe Network Auditor"
name = "sn_auditor"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
homepage = "https://maidsafe.net"
repository = "https://github.com/maidsafe/safe_network"
Expand Down
82 changes: 49 additions & 33 deletions sn_auditor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,43 +308,59 @@ async fn initialize_background_spend_dag_collection(
}

async fn start_server(dag: SpendDagDb) -> Result<()> {
let server = Server::http("0.0.0.0:4242").expect("Failed to start server");
info!("Starting dag-query server listening on port 4242...");
for request in server.incoming_requests() {
info!(
"Received request! method: {:?}, url: {:?}",
request.method(),
request.url(),
);

// Dispatch the request to the appropriate handler
let response = match request.url() {
"/" => routes::spend_dag_svg(&dag),
s if s.starts_with("/spend/") => routes::spend(&dag, &request).await,
s if s.starts_with("/add-participant/") => {
routes::add_participant(&dag, &request).await
}
"/beta-rewards" => routes::beta_rewards(&dag).await,
_ => routes::not_found(),
};
loop {
let server = Server::http("0.0.0.0:4242").expect("Failed to start server");
info!("Starting dag-query server listening on port 4242...");
for request in server.incoming_requests() {
info!(
"Received request! method: {:?}, url: {:?}",
request.method(),
request.url(),
);

// Send a response to the client
match response {
Ok(res) => {
let _ = request
.respond(res)
.map_err(|err| eprintln!("Failed to send response: {err}"));
}
Err(e) => {
eprint!("Sending error to client: {e}");
let res = Response::from_string(format!("Error: {e}")).with_status_code(500);
let _ = request
.respond(res)
.map_err(|err| eprintln!("Failed to send error response: {err}"));
// Dispatch the request to the appropriate handler
let response = match request.url() {
"/" => routes::spend_dag_svg(&dag),
s if s.starts_with("/spend/") => routes::spend(&dag, &request).await,
s if s.starts_with("/add-participant/") => {
routes::add_participant(&dag, &request).await
}
"/beta-rewards" => routes::beta_rewards(&dag).await,
"/restart" => {
info!("Restart auditor web service as to client's request");
break;
}
"/terminate" => {
info!("Terminate auditor web service as to client's request");
return Ok(());
}
_ => routes::not_found(),
};

// Send a response to the client
match response {
Ok(res) => {
info!("Sending response to client");
let _ = request.respond(res).map_err(|err| {
warn!("Failed to send response: {err}");
eprintln!("Failed to send response: {err}")
});
}
Err(e) => {
eprint!("Sending error to client: {e}");
let res = Response::from_string(format!("Error: {e}")).with_status_code(500);
let _ = request.respond(res).map_err(|err| {
warn!("Failed to send error response: {err}");
eprintln!("Failed to send error response: {err}")
});
}
}
}
// Reaching this point indicates a restarting of auditor web service
// Sleep for a while to allowing OS cleanup and settlement.
drop(server);
std::thread::sleep(std::time::Duration::from_secs(10));
}
Ok(())
}

// get the data dir path for auditor
Expand Down

0 comments on commit b069273

Please sign in to comment.