fn next_events(repo: &Repo, service_handler: &ServiceHandler) -> Vec<Event> {
    let ev_status =
        |status: ServiceStatus| Event::new_status_update(service_handler.name(), status);
    let vev_status = |status: ServiceStatus| vec![ev_status(status)];
    match service_handler.status {
        ServiceStatus::Initial if repo.is_service_runnable(service_handler) => {
            vec![Event::Run(service_handler.name().clone())]
        }
        // if enough time have passed, this will be considered running
        ServiceStatus::Started if !service_handler.has_some_failed_healthchecks() => {
            vev_status(ServiceStatus::Running)
        }
        // This will kill the service after 3 failed healthchecks in a row.
        // Maybe this should be parametrized
        ServiceStatus::Running
            if service_handler.healthiness_checks_failed.unwrap_or(-1)
                > service_handler.service.healthiness.max_failed =>
        {
            vec![
                ev_status(ServiceStatus::InKilling),
                Event::Kill(service_handler.name().clone()),
            ]
        }
        ServiceStatus::Success => vec![handle_restart_strategy(service_handler, false)],
        ServiceStatus::Failed => {
            let mut failure_evs = handle_failed_service(
                repo.get_dependents(service_handler.name()),
                service_handler.service(),
            );
            let other_services_termination = repo
                .get_die_if_failed(service_handler.name())
                .into_iter()
                .map(|sh_name| {
                    vec![
                        Event::new_status_update(sh_name, ServiceStatus::InKilling),
                        Event::Kill(sh_name.clone()),
                    ]
                })
                .flatten();

            let service_ev = handle_restart_strategy(service_handler, true);

            failure_evs.push(service_ev);
            failure_evs.extend(other_services_termination);
            failure_evs
        }
        ServiceStatus::InKilling if should_force_kill(service_handler, None) => vec![
            Event::new_force_kill(service_handler.name()),
            Event::new_status_changed(service_handler.name(), ServiceStatus::Failed),
        ],

        _ => vec![],
    }
}
/// Generate the events needed for moving forward the FSM for the service handler
/// If the system is shutting down, it will call next_shutting_down.
Generate the events needed for moving forward the FSM for the service handler
If the system is shutting down, it will call next_shutting_down.
Generate the events needed for moving forward the FSM for the service handler If the system is shutting down it will call next_shutting_down .
fn next_events(repo: &Repo, service_handler: &ServiceHandler) -> Vec<Event> {
    let ev_status =
        |status: ServiceStatus| Event::new_status_update(service_handler.name(), status);
    let vev_status = |status: ServiceStatus| vec![ev_status(status)];
    match service_handler.status {
        ServiceStatus::Initial if repo.is_service_runnable(service_handler) => {
            vec![Event::Run(service_handler.name().clone())]
        }
        // if enough time have passed, this will be considered running
        ServiceStatus::Started if !service_handler.has_some_failed_healthchecks() => {
            vev_status(ServiceStatus::Running)
        }
        // This will kill the service after 3 failed healthchecks in a row.
        // Maybe this should be parametrized
        ServiceStatus::Running
            if service_handler.healthiness_checks_failed.unwrap_or(-1)
                > service_handler.service.healthiness.max_failed =>
        {
            vec![
                ev_status(ServiceStatus::InKilling),
                Event::Kill(service_handler.name().clone()),
            ]
        }
        ServiceStatus::Success => vec![handle_restart_strategy(service_handler, false)],
        ServiceStatus::Failed => {
            let mut failure_evs = handle_failed_service(
                repo.get_dependents(service_handler.name()),
                service_handler.service(),
            );
            let other_services_termination = repo
                .get_die_if_failed(service_handler.name())
                .into_iter()
                .map(|sh_name| {
                    vec![
                        Event::new_status_update(sh_name, ServiceStatus::InKilling),
                        Event::Kill(sh_name.clone()),
                    ]
                })
                .flatten();
            let service_ev = handle_restart_strategy(service_handler, true);
            failure_evs.push(service_ev);
            failure_evs.extend(other_services_termination);
            failure_evs
        }
        ServiceStatus::InKilling if should_force_kill(service_handler, None) => vec![
            Event::new_force_kill(service_handler.name()),
            Event::new_status_changed(service_handler.name(), ServiceStatus::Failed),
        ],
        _ => vec![],
    }
}
fn next_events ( repo : & Repo , service_handler : & ServiceHandler ) -> Vec < Event > { let ev_status = | status : ServiceStatus | Event :: new_status_update ( service_handler . name ( ) , status ) ; let vev_status = | status : ServiceStatus | vec ! [ ev_status ( status ) ] ; match service_handler . status { ServiceStatus :: Initial if repo . is_service_runnable ( service_handler ) => { vec ! [ Event Run ( service_handler name ( ) clone ( ) ) ] } // if enough time have passed, this will be considered running ServiceStatus :: Started if ! service_handler . has_some_failed_healthchecks ( ) => { vev_status ( ServiceStatus :: Running ) } // This will kill the service after 3 failed healthchecks in a row. // Maybe this should be parametrized ServiceStatus :: Running if service_handler . healthiness_checks_failed . unwrap_or ( - 1 ) > service_handler . service . healthiness . max_failed => { vec ! [ ev_status ( ServiceStatus InKilling ) Event Kill ( service_handler name ( ) clone ( ) ) ] } ServiceStatus :: Success => vec ! [ handle_restart_strategy ( service_handler false ) ] , ServiceStatus :: Failed => { let mut failure_evs = handle_failed_service ( repo . get_dependents ( service_handler . name ( ) ) , service_handler . service ( ) , ) ; let other_services_termination = repo . get_die_if_failed ( service_handler . name ( ) ) . into_iter ( ) . map ( | sh_name | { vec ! [ Event new_status_update ( sh_name ServiceStatus InKilling ) Event Kill ( sh_name clone ( ) ) ] } ) . flatten ( ) ; let service_ev = handle_restart_strategy ( service_handler , true ) ; failure_evs . push ( service_ev ) ; failure_evs . extend ( other_services_termination ) ; failure_evs } ServiceStatus :: InKilling if should_force_kill ( service_handler , None ) => vec ! [ Event new_force_kill ( service_handler name ( ) ) Event new_status_changed ( service_handler name ( ) ServiceStatus Failed ) ] , _ => vec ! [ ] , } }
Generate the events needed for moving forward the FSM for the service handler
If the system is shutting down, it will call next_shutting_down.
Generate the events needed for moving forward the FSM for the service handler If the system is shutting down it will call next_shutting_down .
repo
&Repo
service_handler
&ServiceHandler
repo
&Repo
service_handler
&ServiceHandler