You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: mod.rs
    path of file: ./repos/Horust/src/horust/supervisor
    
    the code of the file until where you have to start completion: //! The supervisor is one of the biggest module. It is responsible for supervising the services, and
//! keeping track of their current state.
//! It will also reap the dead processes

use std::fmt::Debug;
use std::ops::Mul;
use std::thread;
use std::time::{Duration, Instant};

use nix::sys::signal;
use nix::unistd;

use repo::Repo;
use service_handler::ServiceHandler;
pub(crate) use signal_handling::init;

use
    
    fn run(mut self) -> ExitStatus {
        while !self.repo.all_have_finished() {
            // Ingest updates
            let received_events = self.repo.get_events();
            debug!("Applying events... {:?}", received_events);
            match (self.status, signal_handling::is_sigterm_received()) {
                (LifecycleStatus::Running, true) => {
                    warn!("1. SIGTERM received");
                    self.repo
                        .send_ev(Event::ShuttingDownInitiated(ShuttingDown::Gracefully));
                }
                (LifecycleStatus::ShuttingDown(ShuttingDown::Gracefully), true) => {
                    warn!("2. SIGTERM received");
                    self.repo
                        .send_ev(Event::ShuttingDownInitiated(ShuttingDown::Forcefully));
                }
                _ => {}
            }
            // Handling of the received events and commands:
            let produced_events = received_events
                .into_iter()
                .flat_map(|ev| self.handle_event(ev))
                .collect::<Vec<Event>>();
            debug!("Produced events: {:?}", produced_events);
            // Producing commands which will be applied in the next iteration
            let next_evs: Vec<Event> = self
                .repo
                .services
                .iter()
                .flat_map(|(_s_name, sh)| sh.next(&self.repo, self.status))
                .chain(reaper::run(&self.repo, MAX_PROCESS_REAPS_ITERS))
                .collect();
            debug!("Next evs: {:?}", next_evs);
            // Dispatch everything via the bus. Since the bus is run by another thread,
            // the next_evs might not arrive in the next batch, leading to possibly duplicated
            // commands.
            produced_events
                .into_iter()
                .chain(next_evs)
                .for_each(|ev| self.repo.send_ev(ev));

            thread::sleep(Duration::from_millis(300));
        }

        debug!("All services have finished");
        // If we're the init system, let's be sure that everything stops before exiting.
        // TODO: Test (probably via docker).
        if unistd::getpid() == INIT_PID {
            let all_processes = unistd::Pid::from_raw(-1);
            let _res = signal::kill(all_processes, signal::SIGTERM);
            thread::sleep(Duration::from_secs(3));
            let _res = signal::kill(all_processes, signal::SIGKILL);
        }

        self.repo
            .send_ev(Event::ShuttingDownInitiated(ShuttingDown::Gracefully));
        if self.repo.any_finished_failed() {
            ExitStatus::SomeServiceFailed
        } else {
            ExitStatus::Successful
        }
    }