Skip to content

Commit

Permalink
rename sozu::Worker::is_not_stopped_or_stopping to is_active
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Mar 16, 2023
1 parent 7d9b0f5 commit 755716c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
6 changes: 1 addition & 5 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,7 @@ impl CommandServer {
}

let mut count = 0usize;
for worker in self
.workers
.iter_mut()
.filter(|worker| worker.is_not_stopped_or_stopping())
{
for worker in self.workers.iter_mut().filter(|worker| worker.is_active()) {
worker.send(message.id.clone(), request.clone()).await;
count += 1;
}
Expand Down
30 changes: 9 additions & 21 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,8 @@ impl CommandServer {
let mut found = false;
let id = format!("LOAD-STATE-{}-{diff_counter}", request.id);

for worker in self
.workers
.iter_mut()
.filter(|worker| worker.is_not_stopped_or_stopping())
for worker in
self.workers.iter_mut().filter(|worker| worker.is_active())
{
let worker_message_id = format!("{}-{}", id, worker.id);
worker
Expand Down Expand Up @@ -549,13 +547,11 @@ impl CommandServer {
client_id, worker_id
);

if !self.workers.iter().any(|worker| {
worker.id == worker_id
&& worker.run_state != RunState::Stopping
&& worker.run_state != RunState::Stopped
// should we add this?
// && worker.run_state != RunState::NotAnswering
}) {
if !self
.workers
.iter()
.any(|worker| worker.id == worker_id && worker.is_active())
{
bail!(format!(
"The worker {} does not exist, or is stopped / stopping.",
&worker_id
Expand Down Expand Up @@ -792,11 +788,7 @@ impl CommandServer {
let mut found = false;
let id = format!("LOAD-STATE-{}-{}", &request.id, diff_counter);

for worker in self
.workers
.iter_mut()
.filter(|worker| worker.is_not_stopped_or_stopping())
{
for worker in self.workers.iter_mut().filter(|worker| worker.is_active()) {
let worker_message_id = format!("{}-{}", id, worker.id);
worker
.send(worker_message_id.clone(), request.content.clone())
Expand Down Expand Up @@ -1212,11 +1204,7 @@ impl CommandServer {
let mut found = false;
let mut stopping_workers = HashSet::new();
let mut worker_count = 0usize;
for worker in self
.workers
.iter_mut()
.filter(|worker| worker.is_not_stopped_or_stopping())
{
for worker in self.workers.iter_mut().filter(|worker| worker.is_active()) {
let should_stop_worker = request == Request::SoftStop || request == Request::HardStop;
if should_stop_worker {
worker.run_state = RunState::Stopping;
Expand Down
2 changes: 1 addition & 1 deletion bin/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Worker {
}
}

pub fn is_not_stopped_or_stopping(&self) -> bool {
pub fn is_active(&self) -> bool {
self.run_state != RunState::Stopping && self.run_state != RunState::Stopped
}

Expand Down

0 comments on commit 755716c

Please sign in to comment.