remove id
and improve naming of logs
This commit is contained in:
parent
6d0a3ec4f2
commit
2809459d8b
5 changed files with 25 additions and 26 deletions
|
@ -35,9 +35,7 @@ pub(crate) struct Config {
|
|||
/// Holds the data for a job
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub(crate) struct Job {
|
||||
/// An ID to identify the job, such as the compilation of a program
|
||||
#[serde(default = "id")]
|
||||
pub(crate) id: String,
|
||||
/// What revision of the job config, temporary until better revision tracking is added
|
||||
#[serde(default = "revision")]
|
||||
pub(crate) revision: String,
|
||||
/// How many threads to limit this job to; recommended to set it to the max threads the job will use
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -3,6 +3,7 @@ use crate::data::*;
|
|||
use better_commands;
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap_complete::aot::{generate, Bash, Elvish, Fish, PowerShell, Zsh};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::create_dir_all;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::fs::write;
|
||||
|
@ -52,38 +53,40 @@ fn main() {
|
|||
fn run(config_path: String) {
|
||||
let config = config_from_file(config_path).unwrap();
|
||||
|
||||
let mut jobs: Vec<Job> = Vec::new();
|
||||
let mut jobs: HashMap<String, Job> = HashMap::new();
|
||||
|
||||
for (package_name, package) in config.clone().packages {
|
||||
|
||||
for (_, package) in config.clone().packages {
|
||||
match package.compilation {
|
||||
Some(tmp) => {
|
||||
jobs.push(tmp);
|
||||
jobs.insert(format!("packages.{}.compilation", package_name), tmp);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
for (_, job) in package.packaging {
|
||||
jobs.push(job);
|
||||
for (packaging_name, job) in package.packaging {
|
||||
jobs.insert(format!("packages.{}.{}", package_name, packaging_name), job);
|
||||
}
|
||||
}
|
||||
|
||||
for (_, job) in config.clone().update_repo {
|
||||
jobs.push(job);
|
||||
for (repo, job) in config.clone().update_repo {
|
||||
jobs.insert(format!("update-repo.{}", repo), job);
|
||||
}
|
||||
|
||||
for job in jobs {
|
||||
println!("{:#?}", run_job(config.clone(), job));
|
||||
for (job_name, job) in jobs {
|
||||
println!("{:#?}", run_job(config.clone(), job_name, job));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
||||
fn run_job(conf: Config, job_name: String, job: Job) -> JobExitStatus {
|
||||
// limit threads to max_threads in the config
|
||||
let mut threads = job.threads;
|
||||
if job.threads > conf.max_threads {
|
||||
threads = conf.max_threads;
|
||||
}
|
||||
|
||||
let container_name: String = format!("gregory-{}-{}-{}", job.id, job.revision, Uuid::now_v7());
|
||||
let container_name: String = format!("gregory-{}-{}-{}", job_name, job.revision, Uuid::now_v7());
|
||||
|
||||
// do job log setup
|
||||
let log_path = &format!("{}/logs/{container_name}", conf.data_dir); // can't select fields in the format!() {} thing, have to do this
|
||||
|
@ -108,6 +111,7 @@ fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
|||
.permissions();
|
||||
PermissionsExt::set_mode(&mut perms, 0o755);
|
||||
|
||||
// run the job
|
||||
let mut cmd_args: Vec<String> = vec![
|
||||
"run".to_string(),
|
||||
format!("--name={container_name}"),
|
||||
|
@ -150,7 +154,8 @@ fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
|||
}
|
||||
},
|
||||
);
|
||||
// remove tmp dir
|
||||
|
||||
// remove tmp dir/clean up
|
||||
remove_dir_all(script_dir).unwrap();
|
||||
|
||||
println!("{:?}", cmd_output);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue