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 # fs/network
kxio = { workspace = true } kxio = { workspace = true }
# Actors
actix-rt = { workspace = true }
[lints.clippy] [lints.clippy]
nursery = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 }
# pedantic = "warn" # pedantic = "warn"

View file

@ -26,8 +26,7 @@ enum Server {
Start, Start,
} }
#[actix_rt::main] fn main() {
async fn main() {
let fs = fs::new(PathBuf::default()); let fs = fs::new(PathBuf::default());
let net = Network::new_real(); let net = Network::new_real();
let repo = git_next_git::repository::real(); let repo = git_next_git::repository::real();
@ -43,7 +42,7 @@ async fn main() {
} }
Server::Start => { Server::Start => {
let sleep_duration = std::time::Duration::from_secs(10); 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, fs: FileSystem,
net: Network, net: Network,
repo: Box<dyn RepositoryFactory>, repo: Box<dyn RepositoryFactory>,
@ -39,22 +39,31 @@ pub async fn start(
init_logging(); init_logging();
info!("Starting Server..."); info!("Starting Server...");
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start(); let execution = async move {
server.do_send(FileUpdated); //-
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
info!("Starting File Watcher..."); info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) { let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) {
Ok(fw) => fw, Ok(fw) => fw,
Err(err) => { Err(err) => {
error!(?err, "Failed to start file watcher"); error!(?err, "Failed to start file watcher");
return; 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() { pub fn init_logging() {