use config::AppConfig; use db::cache::AppCache; use db::database::AppDatabase; use deadpool_redis::cluster::Pool as RedisPool; use slog::Logger; use tokio_util::sync::CancellationToken; pub mod pool; pub mod sync; pub mod webhook_dispatch; pub use pool::{HookWorker, PoolConfig, RedisConsumer}; pub use pool::types::{HookTask, TaskType}; /// Hook service that manages the Redis-backed task queue worker. /// Multiple gitserver pods can run concurrently — the worker acquires a /// per-repo Redis lock before processing each task. #[derive(Clone)] pub struct HookService { pub(crate) db: AppDatabase, pub(crate) cache: AppCache, pub(crate) redis_pool: RedisPool, pub(crate) logger: Logger, pub(crate) config: AppConfig, } impl HookService { pub fn new( db: AppDatabase, cache: AppCache, redis_pool: RedisPool, logger: Logger, config: AppConfig, ) -> Self { Self { db, cache, redis_pool, logger, config, } } /// Start the background worker and return a cancellation token. pub fn start_worker(&self) -> CancellationToken { let pool_config = PoolConfig::from_env(&self.config); pool::start_worker( self.db.clone(), self.cache.clone(), self.redis_pool.clone(), self.logger.clone(), pool_config, ) } }