multi configs seem to work now

This commit is contained in:
Bryson Steck 2025-03-23 20:30:25 -06:00
parent 445ba1fe1f
commit e86793bfdd
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4

View file

@ -245,7 +245,7 @@ impl Refractr {
let r = running.clone();
let count = repos.len();
for i in 0..repos.len() {
current_ints.push(u64::from(
current_ints.push(i64::from(
repos[i].cfg.schedule.interval.unwrap().unsigned_abs(),
));
}
@ -257,11 +257,11 @@ impl Refractr {
.expect("Failed to set ^C handler");
common::verbose(self.verbose, 1, format!("Starting scheduled loop"));
let min = *current_ints.iter().min().unwrap();
let mut do_break = false;
while !do_break {
do_break = true;
let sleep_int = time::Duration::from_secs(min);
let min = *current_ints.iter().min().unwrap();
let sleep_int = time::Duration::from_secs(min as u64);
let now = time::Instant::now();
common::verbose(
@ -270,13 +270,18 @@ impl Refractr {
format!("Sleeping for {} seconds", sleep_int.as_secs()),
);
while running.load(Ordering::SeqCst) {
thread::sleep(time::Duration::from_secs(1));
thread::sleep(time::Duration::from_millis(200));
if now.elapsed().as_secs() >= sleep_int.as_secs() {
common::verbose(self.verbose, 3, format!("Thread has awoken!"));
for i in 0..count {
current_ints[i] -= now.elapsed().as_secs();
if i <= 0 {
current_ints[i] = original_ints[i].clone();
current_ints[i] -= now.elapsed().as_secs() as i64;
common::verbose(
self.verbose,
4,
format!("checking repo: {}", repos[i].cfg.from),
);
if current_ints[i] <= 0 {
common::verbose(self.verbose, 4, format!("repo is ready for push"));
common::verbose(
self.verbose,
2,
@ -287,7 +292,13 @@ impl Refractr {
if let Err(e) = self.push_remotes(&repos[i].cfg, &repos[i].repo, &repos[i].remotes) {
common::error(e, ExitCode::PushError)
};
current_ints[i] = original_ints[i].clone();
}
common::verbose(
self.verbose,
4,
format!("repo remaining time is now {}", current_ints[i]),
);
}
do_break = false;
break;
@ -403,7 +414,12 @@ impl Refractr {
},
};
self.set_up_refs(&repo, &cfg.config.branches).unwrap();
if let Err(e) = self.set_up_refs(&repo, &cfg.config.branches) {
common::error(
format!("failed to set up refs: {}", e),
ExitCode::RepositoryError,
);
}
if let Err(e) = self.fetch(
&repo,
&cfg.config.branches,