WIP: server: ???

This commit is contained in:
Paul Campbell 2024-06-19 07:03:17 +01:00
parent eb28a2b690
commit 0f8320f425
3 changed files with 14 additions and 13 deletions

View file

@ -716,7 +716,7 @@ pub mod given {
pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> GitDir { pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> GitDir {
let dir_name = a_name(); let dir_name = a_name();
let dir = fs.base().join(dir_name); let dir = fs.base().join(dir_name);
GitDir::new(&dir) GitDir::new(dir)
} }
pub fn a_forge_config() -> ForgeConfig { pub fn a_forge_config() -> ForgeConfig {

View file

@ -8,7 +8,7 @@ use git_next_config::{
self as config, ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig, self as config, ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig,
}; };
use git_next_git::{Generation, RepoDetails, Repository}; use git_next_git::{Generation, RepoDetails, Repository};
use git_next_repo_actor::{messages::CloneRepo, RepoActor}; use git_next_repo_actor as repo_actor;
use kxio::{fs::FileSystem, network::Network}; use kxio::{fs::FileSystem, network::Network};
use tracing::{error, info, warn}; use tracing::{error, info, warn};
@ -158,7 +158,7 @@ impl Server {
forge_name: ForgeAlias, forge_name: ForgeAlias,
server_storage: &ServerStorage, server_storage: &ServerStorage,
webhook: &Webhook, webhook: &Webhook,
) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> { ) -> Vec<(ForgeAlias, RepoAlias, repo_actor::RepoActor)> {
let span = let span =
tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config); tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config);
@ -183,13 +183,14 @@ impl Server {
forge_config: ForgeConfig, forge_config: ForgeConfig,
server_storage: &ServerStorage, server_storage: &ServerStorage,
webhook: &Webhook, webhook: &Webhook,
) -> impl Fn((RepoAlias, &ServerRepoConfig)) -> (ForgeAlias, RepoAlias, RepoActor) { ) -> impl Fn((RepoAlias, &ServerRepoConfig)) -> (ForgeAlias, RepoAlias, repo_actor::RepoActor)
{
let server_storage = server_storage.clone(); let server_storage = server_storage.clone();
let webhook = webhook.clone(); let webhook = webhook.clone();
let net = self.net.clone(); let net = self.net.clone();
let repo = self.repo.clone(); let repo = self.repo.clone();
let generation = self.generation; let generation = self.generation;
let sleep_duration = self.sleep_duration.clone(); let sleep_duration = self.sleep_duration;
move |(repo_alias, server_repo_config)| { move |(repo_alias, server_repo_config)| {
let span = tracing::info_span!("create_actor", alias = %repo_alias, config = %server_repo_config); let span = tracing::info_span!("create_actor", alias = %repo_alias, config = %server_repo_config);
let _guard = span.enter(); let _guard = span.enter();
@ -216,7 +217,7 @@ impl Server {
gitdir, gitdir,
); );
info!("Starting Repo Actor"); info!("Starting Repo Actor");
let actor = RepoActor::new( let actor = repo_actor::RepoActor::new(
repo_details, repo_details,
webhook.clone(), webhook.clone(),
generation, generation,
@ -230,13 +231,13 @@ impl Server {
fn start_actor( fn start_actor(
&self, &self,
actor: (ForgeAlias, RepoAlias, RepoActor), actor: (ForgeAlias, RepoAlias, repo_actor::RepoActor),
) -> (RepoAlias, Addr<RepoActor>) { ) -> (RepoAlias, Addr<repo_actor::RepoActor>) {
let (forge_name, repo_alias, actor) = actor; let (forge_name, repo_alias, actor) = actor;
let span = tracing::info_span!("start_actor", forge = %forge_name, repo = %repo_alias); let span = tracing::info_span!("start_actor", forge = %forge_name, repo = %repo_alias);
let _guard = span.enter(); let _guard = span.enter();
let addr = actor.start(); let addr = actor.start();
addr.do_send(CloneRepo); addr.do_send(repo_actor::messages::CloneRepo);
info!("Started"); info!("Started");
(repo_alias, addr) (repo_alias, addr)
} }

View file

@ -1,19 +1,18 @@
//
mod actors; mod actors;
mod config; mod config;
//
use actix::prelude::*; use actix::prelude::*;
use git_next_git::Repository;
use kxio::{fs::FileSystem, network::Network}; use kxio::{fs::FileSystem, network::Network};
use std::path::PathBuf; use std::path::PathBuf;
use tracing::{error, info, level_filters::LevelFilter}; use tracing::{error, info, level_filters::LevelFilter};
use crate::actors::{ use crate::actors::{
file_watcher::{self, FileUpdated}, file_watcher::{self, FileUpdated},
server::Server, server::Server,
}; };
use git_next_git::Repository;
pub fn init(fs: FileSystem) { pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml"; let file_name = "git-next-server.toml";
@ -63,6 +62,7 @@ pub async fn start(
info!("Server running - Press Ctrl-C to stop..."); info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await; let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down..."); info!("Ctrl-C received, shutting down...");
// TODO: (#94) perform a controlled shutdown of server and file watcher
} }
pub fn init_logging() { pub fn init_logging() {