Skip to content

Commit 331b53a

Browse files
refactor: cancelled functions names
1 parent f00b6e1 commit 331b53a

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

agent-control/src/event/cancellation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ use std::time::Duration;
55
pub type CancellationMessage = ();
66

77
impl EventConsumer<CancellationMessage> {
8+
/// Checks whether the consumer is cancelled immediately.
9+
///
10+
/// Calls [`Self::is_cancelled`] with a timeout of zero.
11+
pub fn is_cancelled(&self) -> bool {
12+
self.is_cancelled_with_timeout(Duration::ZERO)
13+
}
14+
815
/// Checks whether the consumer is cancelled for the given timeout.
916
///
1017
/// It returns true if the consumer received a cancellation message or received an error
1118
/// before the provided timeout is elapsed. Otherwise it blocks until the timeout is elapsed
1219
/// and returns false.
13-
pub fn is_cancelled(&self, timeout: Duration) -> bool {
20+
pub fn is_cancelled_with_timeout(&self, timeout: Duration) -> bool {
1421
match self.as_ref().recv_timeout(timeout) {
1522
Ok(_) => true,
1623
Err(RecvTimeoutError::Timeout) => false,
1724
Err(RecvTimeoutError::Disconnected) => true,
1825
}
1926
}
20-
21-
/// Checks whether the consumer is cancelled immediately.
22-
///
23-
/// Calls [`Self::is_cancelled`] with a timeout of zero.
24-
pub fn is_cancelled_immediately(&self) -> bool {
25-
self.is_cancelled(Duration::ZERO)
26-
}
2727
}

agent-control/src/health/health_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ where
311311
event_publisher.publish_health_event(health);
312312

313313
// Check the cancellation signal
314-
if stop_consumer.is_cancelled(interval.into()) {
314+
if stop_consumer.is_cancelled_with_timeout(interval.into()) {
315315
break;
316316
}
317317
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl NotStartedSupervisorK8s {
147147
}
148148

149149
// Check the cancellation signal
150-
if stop_consumer.is_cancelled(interval) {
150+
if stop_consumer.is_cancelled_with_timeout(interval) {
151151
break;
152152
}
153153
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl NotStartedSupervisorOnHost {
217217
if let Some(pid) = *current_pid_clone.lock().unwrap() {
218218
info!(pid = pid, msg = "Stopping executable");
219219
_ = ProcessTerminator::new(pid)
220-
.shutdown(|| process_finished_consumer.is_cancelled(Duration::new(10, 0)));
220+
.shutdown(|| process_finished_consumer.is_cancelled_with_timeout(Duration::new(10, 0)));
221221
} else {
222222
info!(msg = "Executable not running");
223223
}
@@ -246,7 +246,7 @@ impl NotStartedSupervisorOnHost {
246246
info_span!("start_executable", { ID_ATTRIBUTE_NAME } = %agent_id, exec_id)
247247
.entered();
248248

249-
if kill_process_consumer.is_cancelled_immediately() {
249+
if kill_process_consumer.is_cancelled() {
250250
debug!("Supervisor stopped before starting executable");
251251
break;
252252
}
@@ -310,7 +310,7 @@ impl NotStartedSupervisorOnHost {
310310
}
311311
};
312312

313-
if kill_process_consumer.is_cancelled_immediately() {
313+
if kill_process_consumer.is_cancelled() {
314314
info!(supervisor = bin, msg = "Executable terminated");
315315
break;
316316
}
@@ -346,7 +346,7 @@ impl NotStartedSupervisorOnHost {
346346

347347
restart_policy.backoff(|duration| {
348348
// early exit if supervisor timeout is canceled
349-
kill_process_consumer.is_cancelled(duration);
349+
kill_process_consumer.is_cancelled_with_timeout(duration);
350350
});
351351
i += 1;
352352

agent-control/src/utils/thread_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub mod tests {
165165
fn test_thread_context_start_stop_blocking() {
166166
let thread_name = "test-thread";
167167
let callback = |stop_consumer: EventConsumer<CancellationMessage>| loop {
168-
if stop_consumer.is_cancelled(Duration::default()) {
168+
if stop_consumer.is_cancelled_with_timeout(Duration::default()) {
169169
break;
170170
}
171171
};

agent-control/src/version_checker/k8s/checkers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ where
153153
}
154154
}
155155

156-
if stop_consumer.is_cancelled(interval.into()) {
156+
if stop_consumer.is_cancelled_with_timeout(interval.into()) {
157157
break;
158158
}
159159
};

0 commit comments

Comments
 (0)