gitdataai/libs/git/hook/sync/gc.rs
ZhenYi 1fed9fc8ab fix(git/hook): address review findings — fs blocking, redis timeout, backoff, slog
- sync/mod.rs: wrap scan_skills_from_dir in spawn_blocking to avoid
  blocking the async executor; use to_path_buf() to get owned PathBuf
- pool/worker.rs: replace 500ms poll sleep with cancellation-is_cancelled
  check (eliminates artificial latency); add exponential backoff on Redis
  errors (1s base, 32s cap, reset on success)
- pool/redis.rs: add 5s timeout on pool.get() for all three methods
  (next, ack_raw, nak_with_retry) to prevent indefinite blocking on
  unresponsive Redis
- sync/gc.rs: add comment explaining why git gc --auto non-zero exit
  is benign
- webhook_dispatch.rs: remove unnecessary format! wrappers in slog macros
- config/hook.rs: document max_concurrent intent (K8s operator/HPA, not
  the single-threaded worker itself)
2026-04-17 13:20:31 +08:00

32 lines
1.0 KiB
Rust

use crate::GitError;
use crate::hook::sync::HookMetaDataSync;
use std::process::Command;
impl HookMetaDataSync {
pub async fn run_gc(&self) -> Result<(), GitError> {
let storage_path = self.repo.storage_path.clone();
let logger = self.logger.clone();
tokio::task::spawn_blocking(move || {
let status = Command::new("git")
.arg("-C")
.arg(&storage_path)
.arg("gc")
.arg("--auto")
.arg("--quiet")
.status()
.map_err(|e| GitError::IoError(format!("git gc failed: {}", e)))?;
if !status.success() {
// git gc --auto exits non-zero when there's nothing to collect,
// or when another gc is already running — both are benign.
slog::warn!(logger, "git gc exited with {:?}", status.code());
}
Ok::<(), GitError>(())
})
.await
.map_err(|e| GitError::Internal(format!("spawn_blocking join error: {}", e)))?
}
}