WIP: server: ???
This commit is contained in:
parent
bc338d7703
commit
2851059fd6
3 changed files with 51 additions and 23 deletions
|
@ -8,7 +8,7 @@ use git_next_config::{
|
|||
self as config, ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig,
|
||||
};
|
||||
use git_next_git::{Generation, RepoDetails, Repository};
|
||||
use git_next_repo_actor::{CloneRepo, RepoActor};
|
||||
use git_next_repo_actor as repo_actor;
|
||||
use kxio::{fs::FileSystem, network::Network};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
|
@ -39,6 +39,7 @@ pub struct Server {
|
|||
fs: FileSystem,
|
||||
net: Network,
|
||||
repo: Repository,
|
||||
sleep_duration: std::time::Duration,
|
||||
}
|
||||
impl Actor for Server {
|
||||
type Context = Context<Self>;
|
||||
|
@ -100,7 +101,13 @@ impl Handler<ServerConfig> for Server {
|
|||
|
||||
// Forge Actors
|
||||
for (forge_alias, forge_config) in server_config.forges() {
|
||||
self.create_forge_repos(forge_config, forge_alias.clone(), server_storage, webhook)
|
||||
self.create_forge_repos(
|
||||
forge_config,
|
||||
forge_alias.clone(),
|
||||
server_storage,
|
||||
webhook,
|
||||
self.sleep_duration,
|
||||
)
|
||||
.into_iter()
|
||||
.map(|a| self.start_actor(a))
|
||||
.map(|(repo_alias, addr)| {
|
||||
|
@ -114,7 +121,12 @@ impl Handler<ServerConfig> for Server {
|
|||
}
|
||||
}
|
||||
impl Server {
|
||||
pub fn new(fs: FileSystem, net: Network, repo: Repository) -> Self {
|
||||
pub fn new(
|
||||
fs: FileSystem,
|
||||
net: Network,
|
||||
repo: Repository,
|
||||
sleep_duration: std::time::Duration,
|
||||
) -> Self {
|
||||
let generation = Generation::new();
|
||||
Self {
|
||||
generation,
|
||||
|
@ -122,6 +134,7 @@ impl Server {
|
|||
fs,
|
||||
net,
|
||||
repo,
|
||||
sleep_duration,
|
||||
}
|
||||
}
|
||||
fn create_forge_data_directories(
|
||||
|
@ -151,14 +164,21 @@ impl Server {
|
|||
forge_name: ForgeAlias,
|
||||
server_storage: &ServerStorage,
|
||||
webhook: &Webhook,
|
||||
) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> {
|
||||
sleep_duration: std::time::Duration,
|
||||
) -> Vec<(ForgeAlias, RepoAlias, repo_actor::RepoActor)> {
|
||||
let span =
|
||||
tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config);
|
||||
|
||||
let _guard = span.enter();
|
||||
info!("Creating Forge");
|
||||
let mut repos = vec![];
|
||||
let creator = self.create_actor(forge_name, forge_config.clone(), server_storage, webhook);
|
||||
let creator = self.create_actor(
|
||||
forge_name,
|
||||
forge_config.clone(),
|
||||
server_storage,
|
||||
webhook,
|
||||
sleep_duration,
|
||||
);
|
||||
for (repo_alias, server_repo_config) in forge_config.repos() {
|
||||
let forge_repo = creator((repo_alias, server_repo_config));
|
||||
info!(
|
||||
|
@ -176,7 +196,9 @@ impl Server {
|
|||
forge_config: ForgeConfig,
|
||||
server_storage: &ServerStorage,
|
||||
webhook: &Webhook,
|
||||
) -> impl Fn((RepoAlias, &ServerRepoConfig)) -> (ForgeAlias, RepoAlias, RepoActor) {
|
||||
sleep_duration: std::time::Duration,
|
||||
) -> impl Fn((RepoAlias, &ServerRepoConfig)) -> (ForgeAlias, RepoAlias, repo_actor::RepoActor)
|
||||
{
|
||||
let server_storage = server_storage.clone();
|
||||
let webhook = webhook.clone();
|
||||
let net = self.net.clone();
|
||||
|
@ -208,12 +230,13 @@ impl Server {
|
|||
gitdir,
|
||||
);
|
||||
info!("Starting Repo Actor");
|
||||
let actor = RepoActor::new(
|
||||
let actor = repo_actor::RepoActor::new(
|
||||
repo_details,
|
||||
webhook.clone(),
|
||||
generation,
|
||||
net.clone(),
|
||||
repo.clone(),
|
||||
sleep_duration,
|
||||
);
|
||||
(forge_name.clone(), repo_alias, actor)
|
||||
}
|
||||
|
@ -221,13 +244,13 @@ impl Server {
|
|||
|
||||
fn start_actor(
|
||||
&self,
|
||||
actor: (ForgeAlias, RepoAlias, RepoActor),
|
||||
) -> (RepoAlias, Addr<RepoActor>) {
|
||||
actor: (ForgeAlias, RepoAlias, repo_actor::RepoActor),
|
||||
) -> (RepoAlias, Addr<repo_actor::RepoActor>) {
|
||||
let (forge_name, repo_alias, actor) = actor;
|
||||
let span = tracing::info_span!("start_actor", forge = %forge_name, repo = %repo_alias);
|
||||
let _guard = span.enter();
|
||||
let addr = actor.start();
|
||||
addr.do_send(CloneRepo);
|
||||
addr.do_send(repo_actor::messages::CloneRepo);
|
||||
info!("Started");
|
||||
(repo_alias, addr)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ fn test_repo_config_load() -> Result<()> {
|
|||
|
||||
[options]
|
||||
"#;
|
||||
let config = RepoConfig::load(toml)?;
|
||||
let config = RepoConfig::parse(toml)?;
|
||||
|
||||
assert_eq!(
|
||||
config,
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
//
|
||||
mod actors;
|
||||
mod config;
|
||||
//
|
||||
|
||||
use actix::prelude::*;
|
||||
|
||||
use git_next_git::Repository;
|
||||
use kxio::{fs::FileSystem, network::Network};
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tracing::{error, info, level_filters::LevelFilter};
|
||||
|
||||
use crate::actors::{
|
||||
file_watcher::{self, FileUpdated},
|
||||
server::Server,
|
||||
};
|
||||
use git_next_git::Repository;
|
||||
|
||||
pub fn init(fs: FileSystem) {
|
||||
let file_name = "git-next-server.toml";
|
||||
|
@ -37,11 +36,16 @@ pub fn init(fs: FileSystem) {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn start(fs: FileSystem, net: Network, repo: Repository) {
|
||||
pub async fn start(
|
||||
fs: FileSystem,
|
||||
net: Network,
|
||||
repo: Repository,
|
||||
sleep_duration: std::time::Duration,
|
||||
) {
|
||||
init_logging();
|
||||
|
||||
info!("Starting Server...");
|
||||
let server = Server::new(fs.clone(), net.clone(), repo).start();
|
||||
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
|
||||
server.do_send(FileUpdated);
|
||||
|
||||
info!("Starting File Watcher...");
|
||||
|
@ -58,6 +62,7 @@ pub async fn start(fs: FileSystem, net: Network, repo: Repository) {
|
|||
info!("Server running - Press Ctrl-C to stop...");
|
||||
let _ = actix_rt::signal::ctrl_c().await;
|
||||
info!("Ctrl-C received, shutting down...");
|
||||
// TODO: (#94) perform a controlled shutdown of server and file watcher
|
||||
}
|
||||
|
||||
pub fn init_logging() {
|
||||
|
|
Loading…
Reference in a new issue