refactor: merge server crate into cli crate
All checks were successful
Rust / build (push) Successful in 2m17s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful

This commit is contained in:
Paul Campbell 2024-07-27 08:11:52 +01:00
parent 5a595ec9ee
commit 1427284c2a
9 changed files with 118 additions and 123 deletions

View file

@ -13,7 +13,8 @@ categories = { workspace = true }
[dependencies]
git-next-core = { workspace = true }
git-next-server = { workspace = true }
git-next-file-watcher-actor = { workspace = true }
git-next-server-actor = { workspace = true }
# CLI parsing
clap = { workspace = true }
@ -21,6 +22,21 @@ clap = { workspace = true }
# fs/network
kxio = { workspace = true }
# logging
console-subscriber = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
# Actors
actix = { workspace = true }
actix-rt = { workspace = true }
[dev-dependencies]
# Testing
assert2 = { workspace = true }
secrecy = { workspace = true }
test-log = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"

View file

@ -520,8 +520,8 @@ The following diagram shows the dependency between the crates that make up `git-
stateDiagram-v2
cli --> core
cli --> server
cli --> server_actor
cli --> file_watcher_actor
forge --> core
forge --> forge_forgejo
@ -534,10 +534,6 @@ stateDiagram-v2
repo_actor --> core
repo_actor --> forge
server --> core
server --> file_watcher_actor
server --> server_actor
server_actor --> core
server_actor --> forge
server_actor --> repo_actor

View file

@ -1,5 +1,6 @@
//
mod init;
mod server;
#[cfg(test)]
mod tests;
@ -41,11 +42,11 @@ fn main() {
}
Command::Server(server) => match server {
Server::Init => {
git_next_server::init(fs);
server::init(fs);
}
Server::Start => {
let sleep_duration = std::time::Duration::from_secs(10);
git_next_server::start(fs, net, repository_factory, sleep_duration);
server::start(fs, net, repository_factory, sleep_duration);
}
},
}

View file

@ -0,0 +1,92 @@
//
#[cfg(test)]
mod tests;
use actix::prelude::*;
use git_next_core::git::RepositoryFactory;
use git_next_file_watcher_actor::{FileUpdated, FileWatcher};
use git_next_server_actor::ServerActor;
use kxio::{fs::FileSystem, network::Network};
use tracing::{error, info, level_filters::LevelFilter};
use std::path::PathBuf;
pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml";
let pathbuf = PathBuf::from(file_name);
let Ok(exists) = fs.path_exists(&pathbuf) else {
eprintln!("Could not check if file exist: {}", file_name);
return;
};
if exists {
eprintln!(
"The configuration file already exists at {} - not overwritting it.",
file_name
);
} else {
match fs.file_write(&pathbuf, include_str!("server-default.toml")) {
Ok(_) => println!("Created a default configuration file at {}", file_name),
Err(e) => {
eprintln!("Failed to write to the configuration file: {}", e)
}
}
}
}
pub fn start(
fs: FileSystem,
net: Network,
repo: Box<dyn RepositoryFactory>,
sleep_duration: std::time::Duration,
) {
init_logging();
info!("Starting Server...");
let execution = async move {
let server = ServerActor::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.clone().recipient()) {
Ok(fw) => fw,
Err(err) => {
error!(?err, "Failed to start file watcher");
return;
}
};
fw.start();
info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
server.do_send(git_next_server_actor::messages::Shutdown);
actix_rt::time::sleep(std::time::Duration::from_millis(200)).await;
System::current().stop();
};
let system = System::new();
Arbiter::current().spawn(execution);
if let Err(err) = system.run() {
tracing::error!(?err, "")
};
}
pub fn init_logging() {
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
let subscriber = tracing_subscriber::fmt::layer()
.with_target(false)
.with_file(true)
.with_line_number(true)
.with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
);
tracing_subscriber::registry()
.with(console_subscriber::ConsoleLayer::builder().spawn())
.with(subscriber)
.init();
}

View file

@ -4,30 +4,9 @@ version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
description = "server for git-next, the trunk-based development manager"
description = "[deprecated crate] server for git-next, the trunk-based development manager"
[dependencies]
git-next-core = { workspace = true }
git-next-file-watcher-actor = { workspace = true }
git-next-server-actor = { workspace = true }
# logging
console-subscriber = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
# fs/network
kxio = { workspace = true }
# Actors
actix = { workspace = true }
actix-rt = { workspace = true }
[dev-dependencies]
# Testing
assert2 = { workspace = true }
secrecy = { workspace = true }
test-log = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }

View file

@ -7,3 +7,5 @@ development workflows where each commit must pass CI before being included in
the main branch.
See [git-next](https://crates.io/crates/git-next) for more information.
N.B. this crate has been merged into [git-next](https://crates.io/git-next).

View file

@ -1,92 +1 @@
//
#[cfg(test)]
mod tests;
use actix::prelude::*;
use git_next_core::git::RepositoryFactory;
use git_next_file_watcher_actor::{FileUpdated, FileWatcher};
use git_next_server_actor::ServerActor;
use kxio::{fs::FileSystem, network::Network};
use tracing::{error, info, level_filters::LevelFilter};
use std::path::PathBuf;
pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml";
let pathbuf = PathBuf::from(file_name);
let Ok(exists) = fs.path_exists(&pathbuf) else {
eprintln!("Could not check if file exist: {}", file_name);
return;
};
if exists {
eprintln!(
"The configuration file already exists at {} - not overwritting it.",
file_name
);
} else {
match fs.file_write(&pathbuf, include_str!("../server-default.toml")) {
Ok(_) => println!("Created a default configuration file at {}", file_name),
Err(e) => {
eprintln!("Failed to write to the configuration file: {}", e)
}
}
}
}
pub fn start(
fs: FileSystem,
net: Network,
repo: Box<dyn RepositoryFactory>,
sleep_duration: std::time::Duration,
) {
init_logging();
info!("Starting Server...");
let execution = async move {
let server = ServerActor::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.clone().recipient()) {
Ok(fw) => fw,
Err(err) => {
error!(?err, "Failed to start file watcher");
return;
}
};
fw.start();
info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
server.do_send(git_next_server_actor::messages::Shutdown);
actix_rt::time::sleep(std::time::Duration::from_millis(200)).await;
System::current().stop();
};
let system = System::new();
Arbiter::current().spawn(execution);
if let Err(err) = system.run() {
tracing::error!(?err, "")
};
}
pub fn init_logging() {
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
let subscriber = tracing_subscriber::fmt::layer()
.with_target(false)
.with_file(true)
.with_line_number(true)
.with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
);
tracing_subscriber::registry()
.with(console_subscriber::ConsoleLayer::builder().spawn())
.with(subscriber)
.init();
}
// moved to /crates/cli/src/server