feat(server): start repo actors
This commit is contained in:
parent
34c5caaaa1
commit
ca673f9545
1 changed files with 43 additions and 7 deletions
|
@ -1,11 +1,16 @@
|
|||
mod actors;
|
||||
mod config;
|
||||
|
||||
use actix::prelude::*;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tracing::{error, info};
|
||||
|
||||
use crate::filesystem::FileSystem;
|
||||
use crate::{
|
||||
filesystem::FileSystem,
|
||||
server::config::{ForgeName, RepoName},
|
||||
};
|
||||
|
||||
pub fn init(fs: FileSystem) {
|
||||
let file_name = "git-next-server.toml";
|
||||
|
@ -40,19 +45,50 @@ pub fn start(fs: FileSystem) {
|
|||
};
|
||||
info!("Config loaded");
|
||||
info!("Loaded config");
|
||||
config.forges().for_each(|(name, forge)| {
|
||||
let span = tracing::info_span!("Forge", name);
|
||||
let mut actors: Vec<(ForgeName, RepoName, actors::repo::RepoActor)> = vec![];
|
||||
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();
|
||||
info!("Forge: {}", name);
|
||||
info!("Forge: {}", forge_name);
|
||||
info!("Forge Type: {}", forge.forge_type());
|
||||
info!("Hostname: {}", forge.hostname());
|
||||
info!("User: {}", forge.user());
|
||||
forge.repos().for_each(|(name, path)| {
|
||||
let span = tracing::info_span!("Repo", name);
|
||||
forge.repos().for_each(|(repo_name, path)| {
|
||||
let repo_name = RepoName(repo_name.clone());
|
||||
let span = tracing::info_span!("Repo", %repo_name);
|
||||
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> {
|
||||
|
|
Loading…
Reference in a new issue