Skip to content

Commit 75d9ac2

Browse files
committed
fix(job): allow running with stale run/ dir during build
Previously, scheduled runs were skipped entirely while a build was in progress. Now: - If run/ directory exists, jobs run immediately (stale state is OK) - If run/ doesn't exist (first run), wait for build then execute
1 parent 53302ed commit 75d9ac2

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

src/actor/job/mod.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub struct JobActor {
3131
// Build state
3232
build_in_progress: bool,
3333
build_handle: Option<JoinHandle<()>>,
34-
pending_copy: bool, // build done, waiting for execution to finish
35-
run_dir_ready: bool, // run/ directory exists and is ready for execution
34+
pending_copy: bool, // build done, waiting for execution to finish
35+
pending_run: bool, // tick arrived during first build, run after build completes
3636
}
3737

3838
impl JobActor {
@@ -57,7 +57,7 @@ impl JobActor {
5757
build_in_progress: false,
5858
build_handle: None,
5959
pending_copy: false,
60-
run_dir_ready: false,
60+
pending_run: false,
6161
}
6262
}
6363

@@ -68,13 +68,16 @@ impl JobActor {
6868
let run_dir = git::get_run_dir(&self.sot_path, &self.job.id);
6969
git::copy_build_to_run(&build_dir, &run_dir)?;
7070
self.pending_copy = false;
71-
self.run_dir_ready = true;
7271
Ok(true)
7372
} else {
7473
Ok(false)
7574
}
7675
}
7776

77+
fn run_dir_exists(&self) -> bool {
78+
git::get_run_dir(&self.sot_path, &self.job.id).exists()
79+
}
80+
7881
fn cleanup_finished_handles(&mut self) {
7982
self.handles.retain(|h| !h.is_finished());
8083
}
@@ -203,13 +206,23 @@ impl Handler<Tick> for JobActor {
203206
self.start_build(addr.clone());
204207
}
205208

206-
// Check if run directory is ready
207-
if !self.run_dir_ready {
208-
warn!(
209-
target: "rollcron::job",
210-
job_id = %self.job.id,
211-
"Skipped: run directory not ready (build in progress or first run)"
212-
);
209+
// Check if run directory exists
210+
if !self.run_dir_exists() {
211+
// First run: wait for build to complete, then run
212+
if self.build_in_progress {
213+
info!(
214+
target: "rollcron::job",
215+
job_id = %self.job.id,
216+
"Waiting for initial build to complete"
217+
);
218+
self.pending_run = true;
219+
} else {
220+
warn!(
221+
target: "rollcron::job",
222+
job_id = %self.job.id,
223+
"Skipped: run directory not ready and no build in progress"
224+
);
225+
}
213226
return;
214227
}
215228

@@ -280,8 +293,17 @@ impl Handler<BuildCompleted> for JobActor {
280293
if let Some(addr) = &self.runner_addr {
281294
let _ = addr.send(RunnerBuildCompleted { job_id: self.job.id.clone() }).await;
282295
}
296+
297+
// Run job if it was waiting for this build
298+
if self.pending_run {
299+
self.pending_run = false;
300+
if let Some(addr) = self.self_addr.clone() {
301+
self.handle_trigger(addr).await;
302+
}
303+
}
283304
} else {
284305
warn!(target: "rollcron::job", job_id = %self.job.id, "Build failed, keeping old run directory");
306+
self.pending_run = false;
285307
}
286308

287309
// If there's another pending sync (config changed during build), start another build

0 commit comments

Comments
 (0)