refactor: extract file-watcher-actor crate
All checks were successful
Rust / build (push) Successful in 1m29s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-06-29 10:57:18 +01:00
parent 2008afa4dd
commit 52d442f2b0
8 changed files with 45 additions and 36 deletions

View file

@ -11,6 +11,7 @@ members = [
"crates/repo-actor", "crates/repo-actor",
"crates/webhook-actor", "crates/webhook-actor",
"crates/actor-macros", "crates/actor-macros",
"crates/file-watcher-actor",
] ]
[workspace.package] [workspace.package]
@ -32,6 +33,7 @@ git-next-forge-forgejo = { path = "crates/forge-forgejo" }
git-next-forge-github = { path = "crates/forge-github" } git-next-forge-github = { path = "crates/forge-github" }
git-next-repo-actor = { path = "crates/repo-actor" } git-next-repo-actor = { path = "crates/repo-actor" }
git-next-webhook-actor = { path = "crates/webhook-actor" } git-next-webhook-actor = { path = "crates/webhook-actor" }
git-next-file-watcher-actor = { path = "crates/file-watcher-actor" }
git-next-actor-macros = { path = "crates/actor-macros" } git-next-actor-macros = { path = "crates/actor-macros" }
# CLI parsing # CLI parsing

View file

@ -4,26 +4,9 @@ version = { workspace = true }
edition = { workspace = true } edition = { workspace = true }
[dependencies] [dependencies]
# git-next-config = { workspace = true }
# git-next-repo-actor = { workspace = true }
#
# # logging
# tracing = { workspace = true }
#
# # Webhooks
# bytes = { workspace = true }
# warp = { workspace = true }
#
# # boilerplate
# derive_more = { workspace = true }
# Actors # Actors
actix = { workspace = true } actix = { workspace = true }
[dev-dependencies]
# Testing
# assert2 = { workspace = true }
[lints.clippy] [lints.clippy]
nursery = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 }
# pedantic = "warn" # pedantic = "warn"

View file

@ -0,0 +1,35 @@
[package]
name = "git-next-file-watcher-actor"
version = { workspace = true }
edition = { workspace = true }
[dependencies]
# git-next-config = { workspace = true }
# git-next-repo-actor = { workspace = true }
# logging
tracing = { workspace = true }
# file watcher
inotify = { workspace = true }
# Webhooks
# bytes = { workspace = true }
# warp = { workspace = true }
# boilerplate
# derive_more = { workspace = true }
thiserror = { workspace = true }
# Actors
actix = { workspace = true }
[dev-dependencies]
# Testing
# assert2 = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"
unwrap_used = "warn"
expect_used = "warn"

View file

@ -9,6 +9,7 @@ git-next-git = { workspace = true }
git-next-forge = { workspace = true } git-next-forge = { workspace = true }
git-next-repo-actor = { workspace = true } git-next-repo-actor = { workspace = true }
git-next-actor-macros = { workspace = true } git-next-actor-macros = { workspace = true }
git-next-file-watcher-actor = { workspace = true }
git-next-webhook-actor = { workspace = true } git-next-webhook-actor = { workspace = true }
# logging # logging
@ -23,10 +24,6 @@ kxio = { workspace = true }
derive_more = { workspace = true } derive_more = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
# file watcher
inotify = { workspace = true }
# Actors
actix = { workspace = true } actix = { workspace = true }
actix-rt = { workspace = true } actix-rt = { workspace = true }

View file

@ -1,3 +1,2 @@
pub mod file_watcher;
pub mod messages; pub mod messages;
pub mod server; pub mod server;

View file

@ -1,17 +1,16 @@
// //
use std::path::PathBuf;
use crate::actors::file_watcher::FileUpdated;
use actix::prelude::*; use actix::prelude::*;
use config::server::{ServerConfig, ServerStorage, Webhook}; use config::server::{ServerConfig, ServerStorage, Webhook};
use config::{ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig}; use config::{ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig};
use git::{repository::RepositoryFactory, Generation, RepoDetails}; use git::{repository::RepositoryFactory, Generation, RepoDetails};
use git_next_actor_macros::message; use git_next_actor_macros::message;
use git_next_config as config; use git_next_config as config;
use git_next_file_watcher_actor::FileUpdated;
use git_next_git as git; use git_next_git as git;
use git_next_repo_actor::{messages::CloneRepo, RepoActor}; use git_next_repo_actor::{messages::CloneRepo, RepoActor};
use git_next_webhook_actor as webhook; use git_next_webhook_actor as webhook;
use kxio::{fs::FileSystem, network::Network}; use kxio::{fs::FileSystem, network::Network};
use std::path::PathBuf;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use webhook::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter}; use webhook::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter};

View file

@ -1,19 +1,14 @@
mod actors;
mod config;
// //
use crate::actors::server::Server;
use actix::prelude::*; use actix::prelude::*;
use git_next_file_watcher_actor::{FileUpdated, FileWatcher};
use git_next_git::repository::RepositoryFactory; use git_next_git::repository::RepositoryFactory;
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::{ mod actors;
file_watcher::{self, FileUpdated}, mod config;
server::Server,
};
pub fn init(fs: FileSystem) { pub fn init(fs: FileSystem) {
let file_name = "git-next-server.toml"; let file_name = "git-next-server.toml";
@ -50,8 +45,7 @@ pub async fn start(
server.do_send(FileUpdated); server.do_send(FileUpdated);
info!("Starting File Watcher..."); info!("Starting File Watcher...");
let fw = match file_watcher::FileWatcher::new("git-next-server.toml".into(), server.recipient()) let fw = match FileWatcher::new("git-next-server.toml".into(), server.recipient()) {
{
Ok(fw) => fw, Ok(fw) => fw,
Err(err) => { Err(err) => {
error!(?err, "Failed to start file watcher"); error!(?err, "Failed to start file watcher");