Introduce job keys
This commit is contained in:
49
src/lib.rs
49
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<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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user