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
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

View File

@ -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");

View File

@ -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<u32, Job>,
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::Commit<'repository>, 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));
}
}