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,
|
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::{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};
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ pub struct Server {
|
||||||
fs: FileSystem,
|
fs: FileSystem,
|
||||||
net: Network,
|
net: Network,
|
||||||
repo: Repository,
|
repo: Repository,
|
||||||
|
sleep_duration: std::time::Duration,
|
||||||
}
|
}
|
||||||
impl Actor for Server {
|
impl Actor for Server {
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
|
@ -100,7 +101,13 @@ impl Handler<ServerConfig> for Server {
|
||||||
|
|
||||||
// Forge Actors
|
// Forge Actors
|
||||||
for (forge_alias, forge_config) in server_config.forges() {
|
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()
|
.into_iter()
|
||||||
.map(|a| self.start_actor(a))
|
.map(|a| self.start_actor(a))
|
||||||
.map(|(repo_alias, addr)| {
|
.map(|(repo_alias, addr)| {
|
||||||
|
@ -114,7 +121,12 @@ impl Handler<ServerConfig> for Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl 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();
|
let generation = Generation::new();
|
||||||
Self {
|
Self {
|
||||||
generation,
|
generation,
|
||||||
|
@ -122,6 +134,7 @@ impl Server {
|
||||||
fs,
|
fs,
|
||||||
net,
|
net,
|
||||||
repo,
|
repo,
|
||||||
|
sleep_duration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn create_forge_data_directories(
|
fn create_forge_data_directories(
|
||||||
|
@ -151,14 +164,21 @@ impl Server {
|
||||||
forge_name: ForgeAlias,
|
forge_name: ForgeAlias,
|
||||||
server_storage: &ServerStorage,
|
server_storage: &ServerStorage,
|
||||||
webhook: &Webhook,
|
webhook: &Webhook,
|
||||||
) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> {
|
sleep_duration: std::time::Duration,
|
||||||
|
) -> 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);
|
||||||
|
|
||||||
let _guard = span.enter();
|
let _guard = span.enter();
|
||||||
info!("Creating Forge");
|
info!("Creating Forge");
|
||||||
let mut repos = vec![];
|
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() {
|
for (repo_alias, server_repo_config) in forge_config.repos() {
|
||||||
let forge_repo = creator((repo_alias, server_repo_config));
|
let forge_repo = creator((repo_alias, server_repo_config));
|
||||||
info!(
|
info!(
|
||||||
|
@ -176,7 +196,9 @@ 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) {
|
sleep_duration: std::time::Duration,
|
||||||
|
) -> 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();
|
||||||
|
@ -208,12 +230,13 @@ 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,
|
||||||
net.clone(),
|
net.clone(),
|
||||||
repo.clone(),
|
repo.clone(),
|
||||||
|
sleep_duration,
|
||||||
);
|
);
|
||||||
(forge_name.clone(), repo_alias, actor)
|
(forge_name.clone(), repo_alias, actor)
|
||||||
}
|
}
|
||||||
|
@ -221,13 +244,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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn test_repo_config_load() -> Result<()> {
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
"#;
|
"#;
|
||||||
let config = RepoConfig::load(toml)?;
|
let config = RepoConfig::parse(toml)?;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
config,
|
config,
|
||||||
|
|
|
@ -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";
|
||||||
|
@ -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();
|
init_logging();
|
||||||
|
|
||||||
info!("Starting Server...");
|
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);
|
server.do_send(FileUpdated);
|
||||||
|
|
||||||
info!("Starting File Watcher...");
|
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...");
|
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() {
|
||||||
|
|
Loading…
Reference in a new issue