Skip to content

Commit

Permalink
update job status
Browse files Browse the repository at this point in the history
  • Loading branch information
Smehnov committed Aug 5, 2024
1 parent 52cb3f7 commit d35de36
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
49 changes: 29 additions & 20 deletions src/commands/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,37 @@ pub async fn execute_launch(
let args = serde_json::from_str::<DockerLaunchArgs>(&robot_job.args).unwrap();
info!("launching docker job {:?}", args);
let docker_launch = DockerLaunch { args };
let robot_job_result = match docker_launch.execute(robot_job.clone(), agent, jobs).await {
Ok(result) => {
info!("job successfully executed");
result
}
Err(error) => {
error!("error {:?}", error);
RobotJobResult {
job_id: robot_job.id,
status: String::from("error"),
logs: error.to_string(),
{
let exec_jobs = Arc::clone(&jobs);
let robot_job_result = match docker_launch
.execute(robot_job.clone(), agent, exec_jobs)
.await
{
Ok(result) => {
info!("job successfully executed");
result
}
}
};
match socket {
Some(socket) => {
let _ = socket
.emit("job_done", serde_json::json!(robot_job_result))
.await;
}
None => {}
Err(error) => {
error!("error {:?}", error);
RobotJobResult {
job_id: robot_job.id,
status: String::from("error"),
logs: error.to_string(),
}
}
};
let mut job_manager = jobs.lock().unwrap();
job_manager.set_job_result(robot_job_result);
}

// match socket {
// Some(socket) => {
// let _ = socket
// .emit("job_done", serde_json::json!(robot_job_result))
// .await;
// }
// None => {}
// }
}

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down
13 changes: 7 additions & 6 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ pub async fn launch_new_job(
jobs: store::Jobs,
) {
info!("{:?}", robot_job);
let mut job_manager = jobs.lock().unwrap();
job_manager.new_job(
robot_job.id.clone(),
robot_job.job_type.clone(),
robot_job.status.clone(),
);
job_manager.set_job_status(robot_job.id.clone(), "processing".to_string());

match robot_job.job_type.as_str() {
"docker-container-launch" => {
info!("container launch");
let mut job_manager = jobs.lock().unwrap();
job_manager.new_job(
robot_job.id.clone(),
robot_job.job_type.clone(),
robot_job.status.clone(),
);
let shared_jobs = Arc::clone(&jobs);
tokio::spawn(docker::execute_launch(
socket,
Expand Down
11 changes: 10 additions & 1 deletion src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::info;

use base64::{engine::general_purpose, Engine as _};

use crate::commands::RobotJob;
use crate::commands::{RobotJob, RobotJobResult};

#[derive(Debug, Clone, Serialize)]
pub struct Tunnel {
Expand Down Expand Up @@ -115,6 +115,15 @@ impl JobManager {
},
);
}
pub fn set_job_result(&mut self, reslut: RobotJobResult) {
let process = self.data.get_mut(&reslut.job_id);
match process {
Some(process) => {
self.set_job_status(reslut.job_id, reslut.status);
}
None => {}
}
}
pub fn get_job_or_none(&self, job_id: &String) -> Option<JobProcess> {
match self.data.get(job_id) {
Some(job) => Some(job.clone()),
Expand Down

0 comments on commit d35de36

Please sign in to comment.