fix(git-hook): use HookService instead of non-existent GitServiceHooks
Some checks are pending
CI / Rust Lint & Check (push) Waiting to run
CI / Rust Tests (push) Waiting to run
CI / Frontend Lint & Type Check (push) Waiting to run
CI / Frontend Build (push) Blocked by required conditions

GitServiceHooks was renamed to HookService in the hook module refactor.
Updated main.rs to:
- Use HookService::new() with correct parameters (no http client)
- Call start_worker() which returns CancellationToken
- Wait on cancel.cancelled() instead of double-awaiting ctrl_c
- Clone token before moving into signal handler task
This commit is contained in:
ZhenYi 2026-04-17 13:54:17 +08:00
parent 7a2a3c51c4
commit 7c042c7b9d

View File

@ -2,10 +2,9 @@ use clap::Parser;
use config::AppConfig;
use db::cache::AppCache;
use db::database::AppDatabase;
use git::hook::GitServiceHooks;
use git::hook::HookService;
use slog::{Drain, OwnedKVList, Record};
use tokio::signal;
use tokio_util::sync::CancellationToken;
mod args;
@ -29,33 +28,24 @@ async fn main() -> anyhow::Result<()> {
slog::info!(log, "cache connected");
// 5. Parse CLI args
let args = HookArgs::parse();
let _args = HookArgs::parse();
slog::info!(log, "git-hook worker starting";
"worker_id" => %args.worker_id.unwrap_or_else(|| "default".to_string())
);
slog::info!(log, "git-hook worker starting");
// 5. Build HTTP client for webhook delivery
let http = reqwest::Client::builder()
.user_agent("Code-Git-Hook/1.0")
.build()
.unwrap_or_else(|_| reqwest::Client::new());
// 6. Build and run git hook service
let hooks = GitServiceHooks::new(
// 6. Build and start git hook service
let hooks = HookService::new(
db,
cache.clone(),
cache.redis_pool().clone(),
log.clone(),
cfg,
std::sync::Arc::new(http),
);
let cancel = CancellationToken::new();
let cancel_clone = cancel.clone();
// Spawn signal handler
let cancel = hooks.start_worker();
let cancel_signal = cancel.clone();
let log_clone = log.clone();
// Spawn signal handler that cancels on SIGINT/SIGTERM
tokio::spawn(async move {
let ctrl_c = async {
signal::ctrl_c()
@ -82,11 +72,11 @@ async fn main() -> anyhow::Result<()> {
slog::info!(log_clone, "received SIGTERM, initiating shutdown");
}
}
cancel_clone.cancel();
cancel_signal.cancel();
});
hooks.run(cancel).await?;
// Wait until the worker is cancelled (by signal handler or otherwise)
cancel.cancelled().await;
slog::info!(log, "git-hook worker stopped");
Ok(())
}