refactor(repo): use register command for start

feat/mirror-api
Jef Roosens 2024-07-21 19:25:03 +02:00
parent d39205b653
commit 986162e926
Signed by: Jef Roosens
GPG Key ID: 02D4C0997E74717B
2 changed files with 9 additions and 10 deletions

View File

@ -41,7 +41,6 @@ impl SharedState {
pub fn new( pub fn new(
repos_dir: impl AsRef<Path>, repos_dir: impl AsRef<Path>,
conn: DbConn, conn: DbConn,
repos: HashMap<i32, (AtomicU32, Arc<Mutex<()>>)>,
) -> Self { ) -> Self {
let (tx, rx) = unbounded_channel(); let (tx, rx) = unbounded_channel();
@ -50,7 +49,7 @@ impl SharedState {
conn, conn,
rx: Mutex::new(rx), rx: Mutex::new(rx),
tx, tx,
repos: RwLock::new(repos), repos: RwLock::new(Default::default()),
} }
} }
} }
@ -63,7 +62,6 @@ pub fn start(
) -> crate::Result<Handle> { ) -> crate::Result<Handle> {
std::fs::create_dir_all(repos_dir.as_ref())?; std::fs::create_dir_all(repos_dir.as_ref())?;
let mut repos = HashMap::new();
let repo_ids: Vec<i32> = rt.block_on( let repo_ids: Vec<i32> = rt.block_on(
entity::prelude::Repo::find() entity::prelude::Repo::find()
.select_only() .select_only()
@ -72,11 +70,7 @@ pub fn start(
.all(&conn), .all(&conn),
)?; )?;
for id in repo_ids { let state = Arc::new(SharedState::new(repos_dir, conn));
repos.insert(id, Default::default());
}
let state = Arc::new(SharedState::new(repos_dir, conn, repos));
for _ in 0..actors { for _ in 0..actors {
let actor = Actor::new(rt.clone(), Arc::clone(&state)); let actor = Actor::new(rt.clone(), Arc::clone(&state));
@ -84,5 +78,11 @@ pub fn start(
std::thread::spawn(|| actor.run()); std::thread::spawn(|| actor.run());
} }
Ok(Handle::new(&state)) let handle = Handle::new(&state);
for id in repo_ids {
rt.block_on(handle.register_repo(id))?;
}
Ok(handle)
} }

View File

@ -1,5 +1,4 @@
mod pagination; mod pagination;
mod repo;
use crate::db; use crate::db;
use pagination::PaginatedResponse; use pagination::PaginatedResponse;