added job log
parent
d8d482c497
commit
77ecc25132
|
@ -38,6 +38,8 @@ pub enum Commands {
|
|||
page_id: usize
|
||||
},
|
||||
Job {
|
||||
job_id: usize
|
||||
job_id: usize,
|
||||
#[arg(short, long)]
|
||||
log: bool,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
use time::PrimitiveDateTime;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Job {
|
||||
pub file_name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct JobLog {
|
||||
pub content: String,
|
||||
pub upd_ts: PrimitiveDateTime,
|
||||
}
|
||||
|
|
|
@ -48,9 +48,13 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||
let file_service: FileService = container::get_page_service(&mut conn);
|
||||
file_service.get_page(&page_id);
|
||||
}
|
||||
Commands::Job { job_id } => {
|
||||
Commands::Job { job_id, log } => {
|
||||
let mut job_service: JobService = container::get_job_service(&mut conn);
|
||||
job_service.get_job_by_id(&job_id);
|
||||
if log {
|
||||
job_service.get_job_log(&job_id);
|
||||
} else {
|
||||
job_service.get_job_by_id(&job_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use mysql::{params, prelude::Queryable, PooledConn};
|
||||
|
||||
use crate::entity::job::Job;
|
||||
use crate::entity::job::{Job, JobLog};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct JobRepo<'a> {
|
||||
|
@ -35,4 +35,26 @@ impl<'a> JobRepo<'a> {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn find_log(&mut self, job_id: &usize) -> Result<Vec<JobLog>, mysql::Error> {
|
||||
let stat = self
|
||||
.db_pool
|
||||
.prep(
|
||||
"
|
||||
SELECT jea.content, jea.upd_ts
|
||||
FROM jobs j
|
||||
JOIN job_events je on j.job_id = je.job_id AND je.m_id = j.m_id
|
||||
JOIN job_event_attachments jea ON je.job_event_id = jea.job_event_id
|
||||
WHERE
|
||||
j.job_id = :job_id
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
self.db_pool.exec_map(
|
||||
stat,
|
||||
params! {"job_id" => job_id},
|
||||
|( content, upd_ts )| JobLog { content, upd_ts },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::{repository::job_repo::JobRepo, entity::job::Job};
|
||||
use crate::{
|
||||
entity::job::{Job, JobLog},
|
||||
repository::job_repo::JobRepo,
|
||||
};
|
||||
|
||||
pub struct JobService<'a> {
|
||||
pub repo: JobRepo<'a>,
|
||||
|
@ -25,7 +28,26 @@ impl<'a> JobService<'a> {
|
|||
|
||||
println!("{}", "-".repeat(150));
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_job_log(&mut self, job_id: &usize) {
|
||||
let result = self.repo.find_log(job_id);
|
||||
|
||||
match result {
|
||||
Ok(joblog) => {
|
||||
if joblog.is_empty() {
|
||||
println!("Job log not found!");
|
||||
} else {
|
||||
joblog.into_iter().for_each(|joblog: JobLog| {
|
||||
println!("{0: <25} | {1: <20} ", joblog.upd_ts, joblog.content,);
|
||||
});
|
||||
|
||||
println!("{}", "-".repeat(150));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue