refactor(repo): use register command for start
parent
d39205b653
commit
986162e926
|
@ -41,7 +41,6 @@ impl SharedState {
|
|||
pub fn new(
|
||||
repos_dir: impl AsRef<Path>,
|
||||
conn: DbConn,
|
||||
repos: HashMap<i32, (AtomicU32, Arc<Mutex<()>>)>,
|
||||
) -> Self {
|
||||
let (tx, rx) = unbounded_channel();
|
||||
|
||||
|
@ -50,7 +49,7 @@ impl SharedState {
|
|||
conn,
|
||||
rx: Mutex::new(rx),
|
||||
tx,
|
||||
repos: RwLock::new(repos),
|
||||
repos: RwLock::new(Default::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +62,6 @@ pub fn start(
|
|||
) -> crate::Result<Handle> {
|
||||
std::fs::create_dir_all(repos_dir.as_ref())?;
|
||||
|
||||
let mut repos = HashMap::new();
|
||||
let repo_ids: Vec<i32> = rt.block_on(
|
||||
entity::prelude::Repo::find()
|
||||
.select_only()
|
||||
|
@ -72,11 +70,7 @@ pub fn start(
|
|||
.all(&conn),
|
||||
)?;
|
||||
|
||||
for id in repo_ids {
|
||||
repos.insert(id, Default::default());
|
||||
}
|
||||
|
||||
let state = Arc::new(SharedState::new(repos_dir, conn, repos));
|
||||
let state = Arc::new(SharedState::new(repos_dir, conn));
|
||||
|
||||
for _ in 0..actors {
|
||||
let actor = Actor::new(rt.clone(), Arc::clone(&state));
|
||||
|
@ -84,5 +78,11 @@ pub fn start(
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
mod pagination;
|
||||
mod repo;
|
||||
|
||||
use crate::db;
|
||||
use pagination::PaginatedResponse;
|
||||
|
|
Loading…
Reference in New Issue