Skip to content

Commit 90b21e4

Browse files
committed
fix: isolate job heartbeat and contain payload panics
1 parent a65bc29 commit 90b21e4

6 files changed

Lines changed: 212 additions & 28 deletions

File tree

core/src/structs/job.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub enum JobPayload {
111111
steps: u32,
112112
step_sleep_ms: u64,
113113
fail_at: Option<u32>,
114+
panic_at: Option<u32>,
114115
cleanup_marker: Option<String>,
115116
},
116117
}
@@ -414,6 +415,7 @@ mod tests {
414415
steps: 3,
415416
step_sleep_ms: 0,
416417
fail_at: None,
418+
panic_at: None,
417419
cleanup_marker: Some("/tmp/probe-marker".to_string()),
418420
},
419421
user(1, 2),

operations/src/jobs/executor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ pub async fn dispatch_payload(ctx: &JobContext, payload: &JobPayload) -> JobRunO
6666
steps,
6767
step_sleep_ms,
6868
fail_at,
69+
panic_at,
6970
cleanup_marker,
7071
} => {
7172
run_probe(
7273
ctx,
7374
*steps,
7475
*step_sleep_ms,
7576
*fail_at,
77+
*panic_at,
7678
cleanup_marker.as_deref(),
7779
)
7880
.await
@@ -96,6 +98,7 @@ async fn run_probe(
9698
steps: u32,
9799
step_sleep_ms: u64,
98100
fail_at: Option<u32>,
101+
panic_at: Option<u32>,
99102
cleanup_marker: Option<&str>,
100103
) -> JobRunOutcome {
101104
ctx.progress.set_total(steps as u64);
@@ -106,6 +109,9 @@ async fn run_probe(
106109
if ctx.cancel.is_cancelled() {
107110
return JobRunOutcome::Cancelled;
108111
}
112+
if panic_at == Some(step) {
113+
panic!("probe panic at step {step}");
114+
}
109115
if fail_at == Some(step) {
110116
return JobRunOutcome::Failed(JobError::retryable(format!(
111117
"probe failed at step {step}"

operations/src/jobs/prune.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ mod tests {
153153
steps: 1,
154154
step_sleep_ms: 0,
155155
fail_at: None,
156+
panic_at: None,
156157
cleanup_marker: None,
157158
},
158159
UserId::new(Ulid::from_bytes([2u8; 16]), RealmId([1u8; 32])),

0 commit comments

Comments
 (0)