Compare commits

..

No commits in common. "dfc0c1dc8097234daf5a9e44f40dc834778e4d5f" and "40c61fa9ff41c552aee7e08bc359113f47cc0515" have entirely different histories.

4 changed files with 30 additions and 32 deletions

View file

@ -13,6 +13,9 @@ clap = { workspace = true }
# fs/network
kxio = { workspace = true }
# Actors
actix-rt = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"

View file

@ -26,7 +26,8 @@ enum Server {
Start,
}
fn main() {
#[actix_rt::main]
async fn main() {
let fs = fs::new(PathBuf::default());
let net = Network::new_real();
let repo = git_next_git::repository::real();
@ -42,7 +43,7 @@ fn main() {
}
Server::Start => {
let sleep_duration = std::time::Duration::from_secs(10);
git_next_server::start(fs, net, repo, sleep_duration);
git_next_server::start(fs, net, repo, sleep_duration).await;
}
},
}

View file

@ -3,6 +3,7 @@ use actix::prelude::*;
use actix::Recipient;
use inotify::{EventMask, Inotify, WatchMask};
use std::{path::PathBuf, time::Duration};
use tracing::{debug, info};
const CHECK_INTERVAL: Duration = Duration::from_secs(1);
@ -21,6 +22,7 @@ pub enum Error {
}
pub struct FileWatcher {
path: PathBuf,
inotify: Inotify,
recipient: Recipient<FileUpdated>,
run_interval: Option<SpawnHandle>,
@ -29,10 +31,11 @@ impl FileWatcher {
pub fn new(path: PathBuf, recipient: Recipient<FileUpdated>) -> Result<Self, Error> {
let inotify = Inotify::init()?;
inotify.watches().add(
path,
path.clone(),
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE | WatchMask::ATTRIB,
)?;
Ok(Self {
path,
inotify,
recipient,
run_interval: None,
@ -43,7 +46,7 @@ impl Actor for FileWatcher {
type Context = Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
tracing::info!("Starting file watcher actor");
info!("Starting file watcher actor");
self.run_interval
.replace(ctx.run_interval(CHECK_INTERVAL, |_act, ctx| {
ctx.notify(WatchFile);
@ -55,10 +58,11 @@ impl Handler<WatchFile> for FileWatcher {
type Result = ();
fn handle(&mut self, _msg: WatchFile, _ctx: &mut Self::Context) -> Self::Result {
debug!("Watching {} for activity...", self.path.display());
let mut buffer = [0u8; 4096];
if let Ok(mut events) = self.inotify.read_events(&mut buffer) {
if events.any(|event| event.mask.contains(EventMask::MODIFY)) {
tracing::info!("File modified");
info!("File modified");
self.recipient.do_send(FileUpdated);
};
}

View file

@ -5,8 +5,7 @@ use git_next_git::repository::RepositoryFactory;
use git_next_server_actor::Server;
use kxio::{fs::FileSystem, network::Network};
use std::path::PathBuf;
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
use tracing::{error, info, level_filters::LevelFilter};
pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml";
@ -30,7 +29,7 @@ pub fn init(fs: FileSystem) {
}
}
pub fn start(
pub async fn start(
fs: FileSystem,
net: Network,
repo: Box<dyn RepositoryFactory>,
@ -39,31 +38,22 @@ pub fn start(
init_logging();
info!("Starting Server...");
let execution = async move {
//-
let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start();
server.do_send(FileUpdated);
let server = Server::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.recipient()) {
Ok(fw) => fw,
Err(err) => {
error!(?err, "Failed to start file watcher");
return;
}
};
fw.start();
info!("Starting File Watcher...");
let fw = match FileWatcher::new("git-next-server.toml".into(), server.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...");
System::current().stop();
};
let system = System::new();
Arbiter::current().spawn(execution);
if let Err(err) = system.run() {
tracing::error!(?err, "")
};
info!("Server running - Press Ctrl-C to stop...");
let _ = actix_rt::signal::ctrl_c().await;
info!("Ctrl-C received, shutting down...");
}
pub fn init_logging() {
@ -74,7 +64,7 @@ pub fn init_logging() {
.with_target(false)
.with_file(true)
.with_line_number(true)
.with_filter(EnvFilter::from_default_env());
.with_filter(LevelFilter::INFO);
tracing_subscriber::registry()
.with(console_subscriber::ConsoleLayer::builder().spawn())
.with(subscriber)