Introduce job keys

This commit is contained in:
Patrick Lühne 2019-03-02 01:34:16 +01:00
parent a6a1d11b3e
commit 688aa48306
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 30 additions and 33 deletions

View File

@ -8,7 +8,8 @@
tmp_dir=/home/pluehne/tmp tmp_dir=/home/pluehne/tmp
echo "job ID: $JOB_ID" 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" mkdir -p "$tmp_dir"
dir="$tmp_dir"/"job-$JOB_ID" dir="$tmp_dir"/"job-$JOB_ID"
@ -27,10 +28,10 @@ pushd "$dir"
git config user.name "Potassco Bot" git config user.name "Potassco Bot"
git config user.email "bot@potassco.org" 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 sleep 10
start_time=$(date +%s%N) 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 add test-output
git commit -m "Test update" git commit -m "Test update"
git push git push

View File

@ -36,8 +36,8 @@ fn main()
let instance_domain = instance["domain"].as_str().unwrap(); let instance_domain = instance["domain"].as_str().unwrap();
let instance_number = instance["instance"].as_i64().unwrap(); let instance_number = instance["instance"].as_i64().unwrap();
let file_name_base = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number); let job_key = format!("{}/{}/{}/{}", configuration_id, instance_ipc, instance_domain, instance_number);
let file_name_output = format!("{}.out", file_name_base); let file_name_output = format!("{}.out", job_key);
if benchmark_repository.file_exists(Path::new(&file_name_output), "results") if benchmark_repository.file_exists(Path::new(&file_name_output), "results")
{ {
@ -45,12 +45,13 @@ fn main()
continue; continue;
} }
let job = benchmark_repository.create_result_repository(); let job = benchmark_repository.create_job(job_key);
Command::new("sbatch") Command::new("sbatch")
.args(&["/home/pluehne/test-job.sh", "--nodes", "1", "--ntasks-per-node", "1", "-p", "kr"]) .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_RESULT_REPOSITORY_URL", &format!("file://{}", fs::canonicalize(&job.result_repository_path).unwrap().display()))
.env("JOB_ID", format!("{}", job.id)) .env("JOB_ID", format!("{}", job.id))
.env("JOB_KEY", format!("{}", job.key))
.output() .output()
.expect("Could not execute command"); .expect("Could not execute command");

View File

@ -1,17 +1,24 @@
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature}; use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use log::{info, trace}; use log::{info, trace};
use std::collections::HashSet; use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::string::String; use std::string::String;
use std::str; use std::str;
use walkdir::WalkDir; use walkdir::WalkDir;
pub struct Job
{
pub id: u32,
pub key: String,
pub result_repository_path: PathBuf,
}
pub struct BenchmarkRepository pub struct BenchmarkRepository
{ {
base_path: PathBuf, base_path: PathBuf,
repository: Repository, repository: Repository,
jobs: u32, jobs: HashMap<u32, Job>,
ssh_user: String, ssh_user: String,
user_name: String, user_name: String,
user_email: String, user_email: String,
@ -23,12 +30,6 @@ pub struct TargetPath
pub destination: PathBuf, pub destination: PathBuf,
} }
pub struct Job
{
pub id: u32,
pub result_repository_path: PathBuf,
}
impl BenchmarkRepository impl BenchmarkRepository
{ {
fn progress_bar_style() -> ProgressStyle fn progress_bar_style() -> ProgressStyle
@ -144,7 +145,7 @@ impl BenchmarkRepository
{ {
base_path: base_path, base_path: base_path,
repository: repository, repository: repository,
jobs: 0, jobs: HashMap::new(),
ssh_user: ssh_user.to_string(), ssh_user: ssh_user.to_string(),
user_name: user_name.to_string(), user_name: user_name.to_string(),
user_email: user_email.to_string(), user_email: user_email.to_string(),
@ -366,36 +367,30 @@ impl BenchmarkRepository
Some(content.to_owned()) 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)) let id = self.jobs.len() as u32;
} let result_repository_path = self.base_path.join(format!("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);
if result_repository_path.exists() if result_repository_path.exists()
{ {
match std::fs::remove_dir_all(&result_repository_path) match std::fs::remove_dir_all(&result_repository_path)
{ {
Ok(_) => (), 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) match Repository::init_bare(&result_repository_path)
{ {
Ok(repository) => repository, 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::Commit<'repository>, git2::Error> fn tip_commit<'repository>(repository: &'repository git2::Repository, from_remote: bool, branch_name: &str) -> Result<git2::Commit<'repository>, git2::Error>
@ -413,7 +408,7 @@ impl BenchmarkRepository
{ {
let mut active_job_ids = HashSet::new(); 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); active_job_ids.insert(job_id);
} }
@ -424,8 +419,8 @@ impl BenchmarkRepository
( (
|job_id| |job_id|
{ {
let job_repository_path = self.result_repository_path(*job_id); let job = self.jobs.get(job_id).unwrap();
let job_repository = match Repository::open(&job_repository_path) let job_repository = match Repository::open(&job.result_repository_path)
{ {
Ok(value) => value, Ok(value) => value,
Err(error) => panic!("cannot access result repository for job {}: {}", job_id, error), 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)); std::thread::sleep(std::time::Duration::from_secs(2));
} }
} }