pub(crate) fn spawn_fork_exec_handler(
    service: Service,
    backoff: Duration,
    bus: BusConnector<Event>,
) {
    std::thread::spawn(move || {
        let total_sleep = service.start_delay.add(backoff);
        let timeout = after(total_sleep);
        let ticker = tick(Duration::from_millis(100));
        debug!("going to sleep: {:?}", total_sleep);
        // If start-delay is very high, this might interfere with the shutdown of the system.
        // the thread will listen for shutdown events from the bus, and will early exit if there is
        // a shuttingdowninitiated event
        let is_shutting_down_ev = |ev: Event| matches!(ev, Event::ShuttingDownInitiated(_));

        let ev = loop {
            select! {
                    recv(ticker) -> _ => {
                        let is_shutting_down = bus.try_get_events().into_iter().any(is_shutting_down_ev);
                        if is_shutting_down {
                            break Event::SpawnFailed(service.name.clone());
                        }
                    },
                    recv(timeout) -> _ => break match spawn_process(&service) {
                            Ok(pid) => {
                                debug!("Setting pid:{} for service: {}", pid, service.name);
                                Event::new_pid_changed(service.name.clone(), pid)
                            }
                            Err(error) => {
                                error!("Failed spawning the process: {}", error);
                                Event::SpawnFailed(service.name)
                            }
                    },
            }
        };
        bus.send_event(ev);
    });
}
/// Run another thread that will wait for the start delay and handle the fork / exec
Run another thread that will wait for the start delay and handle the fork / exec
Run another thread that will wait for the start delay and handle the fork / exec
pub(crate) fn spawn_fork_exec_handler(
    service: Service,
    backoff: Duration,
    bus: BusConnector<Event>,
) {
    std::thread::spawn(move || {
        let total_sleep = service.start_delay.add(backoff);
        let timeout = after(total_sleep);
        let ticker = tick(Duration::from_millis(100));
        debug!("going to sleep: {:?}", total_sleep);
        // If start-delay is very high, this might interfere with the shutdown of the system.
        // the thread will listen for shutdown events from the bus, and will early exit if there is
        // a shuttingdowninitiated event
        let is_shutting_down_ev = |ev: Event| matches!(ev, Event::ShuttingDownInitiated(_));
        let ev = loop {
            select! {
                    recv(ticker) -> _ => {
                        let is_shutting_down = bus.try_get_events().into_iter().any(is_shutting_down_ev);
                        if is_shutting_down {
                            break Event::SpawnFailed(service.name.clone());
                        }
                    },
                    recv(timeout) -> _ => break match spawn_process(&service) {
                            Ok(pid) => {
                                debug!("Setting pid:{} for service: {}", pid, service.name);
                                Event::new_pid_changed(service.name.clone(), pid)
                            }
                            Err(error) => {
                                error!("Failed spawning the process: {}", error);
                                Event::SpawnFailed(service.name)
                            }
                    },
            }
        };
        bus.send_event(ev);
    });
}
pub ( crate ) fn spawn_fork_exec_handler ( service : Service , backoff : Duration , bus : BusConnector < Event > , ) { std :: thread :: spawn ( move | | { let total_sleep = service . start_delay . add ( backoff ) ; let timeout = after ( total_sleep ) ; let ticker = tick ( Duration :: from_millis ( 100 ) ) ; debug ! ( " " total_sleep ) ; // If start-delay is very high, this might interfere with the shutdown of the system. // the thread will listen for shutdown events from the bus, and will early exit if there is // a shuttingdowninitiated event let is_shutting_down_ev = | ev : Event | matches ! ( ev Event ShuttingDownInitiated ( ) ) ; let ev = loop { select ! { recv ( ticker ) { let is_shutting_down bus try_get_events ( ) into_iter ( ) any ( is_shutting_down_ev ) if is_shutting_down { break Event SpawnFailed ( service name clone ( ) ) } } recv ( timeout ) break match spawn_process ( service ) { Ok ( pid ) { debug ( " " pid service name ) Event new_pid_changed ( service name clone ( ) pid ) } Err ( error ) { error ( " " error ) Event SpawnFailed ( service name ) } } } } ; bus . send_event ( ev ) ; } ) ; }
Run another thread that will wait for the start delay and handle the fork / exec
Run another thread that will wait for the start delay and handle the fork / exec
service
Service
backoff
Duration
bus
BusConnector<Event>
service
Service
backoff
Duration
bus
BusConnector<Event>