feat(server): start repo actors

This commit is contained in:
Paul Campbell 2024-04-07 20:16:04 +01:00
parent 34c5caaaa1
commit ca673f9545

View file

@ -1,11 +1,16 @@
mod actors; mod actors;
mod config; mod config;
use actix::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
use tracing::{error, info}; use tracing::{error, info};
use crate::filesystem::FileSystem; use crate::{
filesystem::FileSystem,
server::config::{ForgeName, RepoName},
};
pub fn init(fs: FileSystem) { pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml"; let file_name = "git-next-server.toml";
@ -40,19 +45,50 @@ pub fn start(fs: FileSystem) {
}; };
info!("Config loaded"); info!("Config loaded");
info!("Loaded config"); info!("Loaded config");
config.forges().for_each(|(name, forge)| { let mut actors: Vec<(ForgeName, RepoName, actors::repo::RepoActor)> = vec![];
let span = tracing::info_span!("Forge", name); config.forges().for_each(|(forge_name, forge)| {
let forge_name = ForgeName(forge_name.clone());
let span = tracing::info_span!("Forge", %forge_name);
let _guard = span.enter(); let _guard = span.enter();
info!("Forge: {}", name); info!("Forge: {}", forge_name);
info!("Forge Type: {}", forge.forge_type()); info!("Forge Type: {}", forge.forge_type());
info!("Hostname: {}", forge.hostname()); info!("Hostname: {}", forge.hostname());
info!("User: {}", forge.user()); info!("User: {}", forge.user());
forge.repos().for_each(|(name, path)| { forge.repos().for_each(|(repo_name, path)| {
let span = tracing::info_span!("Repo", name); let repo_name = RepoName(repo_name.clone());
let span = tracing::info_span!("Repo", %repo_name);
let _guard = span.enter(); let _guard = span.enter();
info!("Repo: {} - {}", name, path); info!("Repo: {} - {}", repo_name, path);
let actor = actors::repo::RepoActor {
defailt: config::RepoDetails {
name: repo_name.clone(),
path: config::RepoPath(path.clone()),
forge: (&forge_name, forge).into(),
},
};
actors.push((forge_name.clone(), repo_name.clone(), actor));
info!("Created actor for repo: {} - {}", repo_name, path);
}); });
}); });
info!("Sending StartRepo to all actors...");
actix::System::new().block_on(async {
let mut addresses: Vec<Addr<actors::repo::RepoActor>> = vec![];
actors.into_iter().for_each(|actor| {
let (forge_name, repo_name, actor) = actor;
let span = tracing::info_span!("Forge/Repo", %forge_name, %repo_name);
let _guard = span.enter();
info!("Starting actor");
let addr = actor.start();
info!("Sending StartRepo to actor");
addr.do_send(actors::repo::StartRepo);
addresses.push(addr);
info!("Sent StartRepo to actor");
});
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
drop(addresses);
});
} }
pub fn init_logging() -> Result<(), tracing::subscriber::SetGlobalDefaultError> { pub fn init_logging() -> Result<(), tracing::subscriber::SetGlobalDefaultError> {