use dashmap::DashMap;
use reqwest::Client;
use std::sync::Arc;
use tokio::sync::Mutex;
use crate::config::Config;
pub type RepoLock = Arc<Mutex<()>>;
#[derive(Clone)]
pub struct AppState {
pub config: Arc<Config>,
pub http_client: Client,
repo_locks: Arc<DashMap<String, RepoLock>>,
}
impl AppState {
pub fn new(config: Config) -> Self {
Self {
config: Arc::new(config),
http_client: Client::new(),
repo_locks: Arc::new(DashMap::new()),
}
}
pub fn get_repo_lock(&self, tenant_id: &str) -> RepoLock {
self.repo_locks
.entry(tenant_id.to_string())
.or_insert_with(|| Arc::new(Mutex::new(())))
.clone()
}
pub fn remove_repo_lock(&self, tenant_id: &str) {
self.repo_locks.remove(tenant_id);
}
}