refactor: only start actor system when server starts
All checks were successful
Rust / build (push) Successful in 1m27s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-07-01 06:54:07 +01:00
parent 77d35e8a09
commit dfc0c1dc80
3 changed files with 26 additions and 21 deletions

View file

@ -13,9 +13,6 @@ clap = { workspace = true }
# fs/network
kxio = { workspace = true }
# Actors
actix-rt = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"

View file

@ -26,8 +26,7 @@ enum Server {
Start,
}
#[actix_rt::main]
async fn main() {
fn main() {
let fs = fs::new(PathBuf::default());
let net = Network::new_real();
let repo = git_next_git::repository::real();
@ -43,7 +42,7 @@ async fn main() {
}
Server::Start => {
let sleep_duration = std::time::Duration::from_secs(10);
git_next_server::start(fs, net, repo, sleep_duration).await;
git_next_server::start(fs, net, repo, sleep_duration);
}
},
}

View file

@ -30,7 +30,7 @@ pub fn init(fs: FileSystem) {
}
}
pub async fn start(
pub fn start(
fs: FileSystem,
net: Network,
repo: Box<dyn RepositoryFactory>,
@ -39,22 +39,31 @@ pub async fn start(
init_logging();
info!("Starting Server...");
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
let execution = async move {
//-
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) {
Ok(fw) => fw,
Err(err) => {
error!(?err, "Failed to start file watcher");
return;
}
info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) {
Ok(fw) => fw,
Err(err) => {
error!(?err, "Failed to start file watcher");
return;
}
};
fw.start();
info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
System::current().stop();
};
let system = System::new();
Arbiter::current().spawn(execution);
if let Err(err) = system.run() {
tracing::error!(?err, "")
};
fw.start();
info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
}
pub fn init_logging() {