add workingthread
This commit is contained in:
@@ -36,7 +36,7 @@ pub enum IdeState {
|
||||
DELETED,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Hash, JsonSchema)]
|
||||
#[derive(Serialize, Deserialize, Hash, JsonSchema, Clone)]
|
||||
pub struct OpenGitParam {
|
||||
pub inquirer: String,
|
||||
pub clone_url: String,
|
||||
|
||||
@@ -11,6 +11,7 @@ use rocket::http::Status;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
|
||||
// podman create --name test -p 3000:3000 -v $PWD:/nixide -w /nixide docker.io/nixos/nix nix-shell --pure start-ide.nix --run run_ide.sh
|
||||
|
||||
@@ -38,6 +39,13 @@ pub struct PodmanContainerList {
|
||||
container: Vec<PodmanContainer>,
|
||||
}
|
||||
|
||||
struct ThreadRunningParam {
|
||||
ide_folder: String,
|
||||
container: PodmanContainer,
|
||||
param: OpenGitParam,
|
||||
working_folder: PathBuf,
|
||||
}
|
||||
|
||||
pub struct PodmanEngine {
|
||||
working_folder: PathBuf,
|
||||
list: PodmanContainerList,
|
||||
@@ -85,6 +93,7 @@ struct PodmanIdeStatus {
|
||||
ide_state: IdeState,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PodmanEngineTraitImpl {
|
||||
working_folder: PathBuf,
|
||||
}
|
||||
@@ -131,22 +140,21 @@ impl NixIdeManageServiceEngine for PodmanEngineTraitImpl {
|
||||
ide_param,
|
||||
};
|
||||
|
||||
eng.list.container.push(container);
|
||||
eng.list.container.push(container.clone());
|
||||
eng.save()
|
||||
.map_err(|_| Status::new(500, "internal error: can't save curent state"))?;
|
||||
|
||||
fetch_sources(&format!("{}/repo", ide_folder), param)
|
||||
.map_err(|_| Status::new(500, "internal error"))?;
|
||||
match eng.find_mut_first_container(ide_id) {
|
||||
Some(i) => {
|
||||
i.state = PodmanState::StartingContainer;
|
||||
eng.save().map_err(|_| {
|
||||
Status::new(500, "internal error: can't save curent state")
|
||||
})?;
|
||||
}
|
||||
_ => {}
|
||||
let thread_param = ThreadRunningParam {
|
||||
ide_folder,
|
||||
container,
|
||||
param: param.clone(),
|
||||
working_folder: eng.working_folder,
|
||||
};
|
||||
|
||||
thread::spawn(move || {
|
||||
working_thread(thread_param);
|
||||
});
|
||||
|
||||
Ok(IdeState::OPENING)
|
||||
}
|
||||
}
|
||||
@@ -246,6 +254,20 @@ fn fetch_sources(repo_path: &str, param: &OpenGitParam) -> Result<(), std::io::E
|
||||
}
|
||||
}
|
||||
|
||||
fn working_thread(thread_param: ThreadRunningParam) {
|
||||
let ide_folder = thread_param.ide_folder;
|
||||
let param = thread_param.param;
|
||||
fetch_sources(&format!("{}/repo", ide_folder), ¶m).unwrap();
|
||||
let mut eng = PodmanEngine::_new(thread_param.working_folder);
|
||||
let ide_id = thread_param.container.ide_id;
|
||||
match eng.find_mut_first_container(&ide_id) {
|
||||
Some(i) => {
|
||||
i.state = PodmanState::StartingContainer;
|
||||
eng.save().unwrap();
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
#[test]
|
||||
fn test_fetch_sources() {
|
||||
let now = std::time::SystemTime::now()
|
||||
|
||||
Reference in New Issue
Block a user