Skip to content

Commit

Permalink
added a server module for launching the API and HTTP services (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheroz authored Nov 6, 2023
1 parent d33feec commit 9887dd3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions anor-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ anor-storage = { path = "../anor-storage"}

[build-dependencies]
prost-build = "0.12.1"

2 changes: 1 addition & 1 deletion anor-api/src/proto/api_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package anor_service_protobuf;

message Keys {
repeated string key = 1;
}
}
17 changes: 11 additions & 6 deletions anor-api/src/service/api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use anor_utils::{config::Config, threadpool::ThreadPool};

pub trait ApiService {
fn with_config(storage: Storage, config: Arc<Config>) -> Self;
fn start(&self, server_shutdown: Arc<AtomicBool>, signal_server_ready: Sender<()>) -> Result<(), String>;
fn start(
&self,
server_shutdown: Arc<AtomicBool>,
signal_server_ready: Sender<()>,
) -> Result<(), String>;
fn stop(&self);
fn keys(&self) -> Vec<String>;
fn set_item(&self, key: &str, item: StorageItem) -> bool;
Expand All @@ -31,7 +35,11 @@ impl ApiService for StorageApi {
StorageApi { storage, config }
}

fn start(&self, shutdown: Arc<AtomicBool>, signal_ready_sender: Sender<()>) -> Result<(), String> {
fn start(
&self,
shutdown: Arc<AtomicBool>,
signal_ready_sender: Sender<()>,
) -> Result<(), String> {
assert!(self.config.api.is_some());
let config_server = self.config.api.as_ref().unwrap();
assert!(!config_server.listen_on.is_empty());
Expand All @@ -44,10 +52,7 @@ impl ApiService for StorageApi {
return Err(err.to_string());
}

log::info!(
"Anor Storage API service listening on {} ...",
listen_on
);
log::info!("Anor Storage API service listening on {} ...", listen_on);
// listener.set_nonblocking(true).unwrap();

let pool = ThreadPool::new(2);
Expand Down
2 changes: 1 addition & 1 deletion anor-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## 0.1.1 (2023-11-03)
## Unreleased

* project moved into anor workspace
* added http service
Expand Down
1 change: 1 addition & 0 deletions anor-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ http_common = "0.2.2"

anor-utils = { path = "../anor-utils"}
anor-storage = { path = "../anor-storage"}

2 changes: 1 addition & 1 deletion anor-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

## 0.1.1 (2023-11-06)
## Unreleased

* project moved into anor workspace

Expand Down
1 change: 0 additions & 1 deletion anor-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ anor-storage = { path = "../anor-storage"}
anor-api = { path = "../anor-api"}
anor-http = { path = "../anor-http"}
anor-utils = { path = "../anor-utils"}

0 comments on commit 9887dd3

Please sign in to comment.