add workingthread
This commit is contained in:
@@ -36,7 +36,7 @@ pub enum IdeState {
|
|||||||
DELETED,
|
DELETED,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Hash, JsonSchema)]
|
#[derive(Serialize, Deserialize, Hash, JsonSchema, Clone)]
|
||||||
pub struct OpenGitParam {
|
pub struct OpenGitParam {
|
||||||
pub inquirer: String,
|
pub inquirer: String,
|
||||||
pub clone_url: String,
|
pub clone_url: String,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use rocket::http::Status;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
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
|
// 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>,
|
container: Vec<PodmanContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ThreadRunningParam {
|
||||||
|
ide_folder: String,
|
||||||
|
container: PodmanContainer,
|
||||||
|
param: OpenGitParam,
|
||||||
|
working_folder: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PodmanEngine {
|
pub struct PodmanEngine {
|
||||||
working_folder: PathBuf,
|
working_folder: PathBuf,
|
||||||
list: PodmanContainerList,
|
list: PodmanContainerList,
|
||||||
@@ -85,6 +93,7 @@ struct PodmanIdeStatus {
|
|||||||
ide_state: IdeState,
|
ide_state: IdeState,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct PodmanEngineTraitImpl {
|
pub struct PodmanEngineTraitImpl {
|
||||||
working_folder: PathBuf,
|
working_folder: PathBuf,
|
||||||
}
|
}
|
||||||
@@ -131,22 +140,21 @@ impl NixIdeManageServiceEngine for PodmanEngineTraitImpl {
|
|||||||
ide_param,
|
ide_param,
|
||||||
};
|
};
|
||||||
|
|
||||||
eng.list.container.push(container);
|
eng.list.container.push(container.clone());
|
||||||
eng.save()
|
eng.save()
|
||||||
.map_err(|_| Status::new(500, "internal error: can't save curent state"))?;
|
.map_err(|_| Status::new(500, "internal error: can't save curent state"))?;
|
||||||
|
|
||||||
fetch_sources(&format!("{}/repo", ide_folder), param)
|
let thread_param = ThreadRunningParam {
|
||||||
.map_err(|_| Status::new(500, "internal error"))?;
|
ide_folder,
|
||||||
match eng.find_mut_first_container(ide_id) {
|
container,
|
||||||
Some(i) => {
|
param: param.clone(),
|
||||||
i.state = PodmanState::StartingContainer;
|
working_folder: eng.working_folder,
|
||||||
eng.save().map_err(|_| {
|
|
||||||
Status::new(500, "internal error: can't save curent state")
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
working_thread(thread_param);
|
||||||
|
});
|
||||||
|
|
||||||
Ok(IdeState::OPENING)
|
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]
|
#[test]
|
||||||
fn test_fetch_sources() {
|
fn test_fetch_sources() {
|
||||||
let now = std::time::SystemTime::now()
|
let now = std::time::SystemTime::now()
|
||||||
|
|||||||
Reference in New Issue
Block a user