From 688aa48306e67364e1347a917b13e3a9ed853eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 2 Mar 2019 01:34:16 +0100 Subject: [PATCH] Introduce job keys --- examples/test-job.sh | 7 ++++--- examples/test.rs | 7 ++++--- src/lib.rs | 49 ++++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/examples/test-job.sh b/examples/test-job.sh index f0c43a7..957447f 100755 --- a/examples/test-job.sh +++ b/examples/test-job.sh @@ -8,7 +8,8 @@ tmp_dir=/home/pluehne/tmp echo "job ID: $JOB_ID" -echo "result repository: $JOB_RESULT_REPOSITORY_URL" +echo "job key: $JOB_KEY" +echo "job result repository URL: $JOB_RESULT_REPOSITORY_URL" mkdir -p "$tmp_dir" dir="$tmp_dir"/"job-$JOB_ID" @@ -27,10 +28,10 @@ pushd "$dir" git config user.name "Potassco Bot" git config user.email "bot@potassco.org" - echo "start of benchmark output of job $JOB_ID" > test-output + echo "start of benchmark output of job $JOB_KEY" > test-output sleep 10 start_time=$(date +%s%N) - echo "end of benchmark output of job $JOB_ID" >> test-output + echo "end of benchmark output of job $JOB_KEY" >> test-output git add test-output git commit -m "Test update" git push diff --git a/examples/test.rs b/examples/test.rs index 0eb9ff2..d10329c 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -36,8 +36,8 @@ fn main() let instance_domain = instance["domain"].as_str().unwrap(); let instance_number = instance["instance"].as_i64().unwrap(); - let file_name_base = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number); - let file_name_output = format!("{}.out", file_name_base); + let job_key = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number); + let file_name_output = format!("{}.out", job_key); if benchmark_repository.file_exists(Path::new(&file_name_output), "results") { @@ -45,12 +45,13 @@ fn main() continue; } - let job = benchmark_repository.create_result_repository(); + let job = benchmark_repository.create_job(job_key); Command::new("sbatch") .args(&["/home/pluehne/test-job.sh", "--nodes", "1", "--ntasks-per-node", "1", "-p", "kr"]) .env("JOB_RESULT_REPOSITORY_URL", &format!("file://{}", fs::canonicalize(&job.result_repository_path).unwrap().display())) .env("JOB_ID", format!("{}", job.id)) + .env("JOB_KEY", format!("{}", job.key)) .output() .expect("Could not execute command"); diff --git a/src/lib.rs b/src/lib.rs index 6bf878e..7cfbe21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,24 @@ use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature}; use indicatif::{ProgressBar, ProgressStyle}; use log::{info, trace}; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::string::String; use std::str; use walkdir::WalkDir; +pub struct Job +{ + pub id: u32, + pub key: String, + pub result_repository_path: PathBuf, +} + pub struct BenchmarkRepository { base_path: PathBuf, repository: Repository, - jobs: u32, + jobs: HashMap, ssh_user: String, user_name: String, user_email: String, @@ -23,12 +30,6 @@ pub struct TargetPath pub destination: PathBuf, } -pub struct Job -{ - pub id: u32, - pub result_repository_path: PathBuf, -} - impl BenchmarkRepository { fn progress_bar_style() -> ProgressStyle @@ -144,7 +145,7 @@ impl BenchmarkRepository { base_path: base_path, repository: repository, - jobs: 0, + jobs: HashMap::new(), ssh_user: ssh_user.to_string(), user_name: user_name.to_string(), user_email: user_email.to_string(), @@ -366,36 +367,30 @@ impl BenchmarkRepository Some(content.to_owned()) } - fn result_repository_path(&self, job_id: u32) -> PathBuf + pub fn create_job(&mut self, key: String) -> &Job { - self.base_path.join(format!("job-{}", job_id)) - } - - pub fn create_result_repository(&mut self) -> Job - { - let job_id = self.jobs; - self.jobs += 1; - - let result_repository_path = self.result_repository_path(job_id); + let id = self.jobs.len() as u32; + let result_repository_path = self.base_path.join(format!("job-{}", id)); if result_repository_path.exists() { match std::fs::remove_dir_all(&result_repository_path) { Ok(_) => (), - Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, result_repository_path.display(), error), + Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", id, result_repository_path.display(), error), }; } match Repository::init_bare(&result_repository_path) { Ok(repository) => repository, - Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, result_repository_path.display(), error), + Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", id, result_repository_path.display(), error), }; - info!("Initialized result Git repository for job {} in “{}”", job_id, result_repository_path.display()); + info!("Initialized result Git repository for job {} in “{}”", id, result_repository_path.display()); - Job{id: job_id, result_repository_path} + self.jobs.insert(id, Job{id, key, result_repository_path}); + self.jobs.get(&id).unwrap() } fn tip_commit<'repository>(repository: &'repository git2::Repository, from_remote: bool, branch_name: &str) -> Result, git2::Error> @@ -413,7 +408,7 @@ impl BenchmarkRepository { let mut active_job_ids = HashSet::new(); - for job_id in 0..self.jobs + for (job_id, _) in &self.jobs { active_job_ids.insert(job_id); } @@ -424,8 +419,8 @@ impl BenchmarkRepository ( |job_id| { - let job_repository_path = self.result_repository_path(*job_id); - let job_repository = match Repository::open(&job_repository_path) + let job = self.jobs.get(job_id).unwrap(); + let job_repository = match Repository::open(&job.result_repository_path) { Ok(value) => value, Err(error) => panic!("cannot access result repository for job {}: {}", job_id, error), @@ -450,7 +445,7 @@ impl BenchmarkRepository } ); - println!("================"); + println!("..."); std::thread::sleep(std::time::Duration::from_secs(2)); } }