Skip to content

Commit 17c5b9a

Browse files
refactor: restart helper function
1 parent 2546b3f commit 17c5b9a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

agent-control/src/sub_agent/on_host/supervisor.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ impl NotStartedSupervisorOnHost {
268268
}
269269

270270
i += 1;
271-
if !restart_process_thread(&mut restart_policy, i, &stop_consumer) {
271+
let restart_cancelled = wait_restart(&mut restart_policy, i, &stop_consumer);
272+
if restart_cancelled {
272273
break;
273274
}
274275
}
@@ -328,26 +329,24 @@ fn wait_exit(
328329
.map(|exit_status| (exit_status, was_cancelled))
329330
}
330331

331-
/// Waits for the restart policy backoff timeout to complete
332-
///
333-
/// If the [`CancellationMessage`] while waiting, the restart will be aborted.
334-
fn restart_process_thread(
332+
/// Waits for the restart policy backoff timeout and returns whether it was cancelled or not
333+
fn wait_restart(
335334
restart_policy: &mut RestartPolicy,
336335
step: u32,
337336
stop_consumer: &EventConsumer<CancellationMessage>,
338337
) -> bool {
339338
let max_retries = restart_policy.backoff.max_retries();
340339
info!("Restarting supervisor ({step}/{max_retries})");
341340

342-
let mut restart = true;
341+
let mut cancelled = false;
343342
restart_policy.backoff(|duration| {
344343
// early exit if supervisor timeout is canceled
345344
if stop_consumer.is_cancelled_with_timeout(duration) {
346-
restart = false;
345+
cancelled = true;
347346
}
348347
});
349348

350-
restart
349+
cancelled
351350
}
352351

353352
/// Executes operations based on the exit status of the command

0 commit comments

Comments
 (0)