forked from kemitix/git-next
refactor: merge server crate into cli crate
This commit is contained in:
parent
5a595ec9ee
commit
1427284c2a
9 changed files with 118 additions and 123 deletions
|
@ -13,7 +13,8 @@ categories = { workspace = true }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
git-next-core = { workspace = true }
|
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
|
# CLI parsing
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
|
@ -21,6 +22,21 @@ clap = { workspace = true }
|
||||||
# fs/network
|
# fs/network
|
||||||
kxio = { workspace = true }
|
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]
|
[lints.clippy]
|
||||||
nursery = { level = "warn", priority = -1 }
|
nursery = { level = "warn", priority = -1 }
|
||||||
# pedantic = "warn"
|
# pedantic = "warn"
|
||||||
|
|
|
@ -520,8 +520,8 @@ The following diagram shows the dependency between the crates that make up `git-
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
|
|
||||||
cli --> core
|
cli --> core
|
||||||
|
cli --> server_actor
|
||||||
cli --> server
|
cli --> file_watcher_actor
|
||||||
|
|
||||||
forge --> core
|
forge --> core
|
||||||
forge --> forge_forgejo
|
forge --> forge_forgejo
|
||||||
|
@ -534,10 +534,6 @@ stateDiagram-v2
|
||||||
repo_actor --> core
|
repo_actor --> core
|
||||||
repo_actor --> forge
|
repo_actor --> forge
|
||||||
|
|
||||||
server --> core
|
|
||||||
server --> file_watcher_actor
|
|
||||||
server --> server_actor
|
|
||||||
|
|
||||||
server_actor --> core
|
server_actor --> core
|
||||||
server_actor --> forge
|
server_actor --> forge
|
||||||
server_actor --> repo_actor
|
server_actor --> repo_actor
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//
|
//
|
||||||
mod init;
|
mod init;
|
||||||
|
mod server;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -41,11 +42,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
Command::Server(server) => match server {
|
Command::Server(server) => match server {
|
||||||
Server::Init => {
|
Server::Init => {
|
||||||
git_next_server::init(fs);
|
server::init(fs);
|
||||||
}
|
}
|
||||||
Server::Start => {
|
Server::Start => {
|
||||||
let sleep_duration = std::time::Duration::from_secs(10);
|
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);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
92
crates/cli/src/server/mod.rs
Normal file
92
crates/cli/src/server/mod.rs
Normal 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();
|
||||||
|
}
|
|
@ -4,30 +4,9 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
license = { workspace = true }
|
license = { workspace = true }
|
||||||
repository = { 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]
|
[lints.clippy]
|
||||||
nursery = { level = "warn", priority = -1 }
|
nursery = { level = "warn", priority = -1 }
|
||||||
|
|
|
@ -7,3 +7,5 @@ development workflows where each commit must pass CI before being included in
|
||||||
the main branch.
|
the main branch.
|
||||||
|
|
||||||
See [git-next](https://crates.io/crates/git-next) for more information.
|
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).
|
||||||
|
|
|
@ -1,92 +1 @@
|
||||||
//
|
// moved to /crates/cli/src/server
|
||||||
#[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();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue