Function handle_signals

Source
pub fn handle_signals(
    term: Arc<AtomicBool>,
    signal_handler_channels: SignalHandlerChannels,
    execution_config: ExecutionConfig,
)
Expand description

Handles operating system termination signals (e.g., SIGTERM).

Upon receiving a termination signal, this function orchestrates a safe, multiphase shutdown of all application threads. It sends specific InternalCommand messages (Quit then Terminate) to each module in a predetermined order, ensuring dependencies are gracefully shut down before their consumers.

§Arguments

  • term - An atomic boolean flag that becomes true when a termination signal is received from the operating system. The function continuously monitors this flag.
  • signal_handler_channels - A struct containing all necessary mpsc sender and receiver channel pairs for communicating with different application threads and modules.

§Panics

  • If signal_handler_channels contains an inconsistent setup for TCP communication (e.g., a sender but no receiver, or vice versa).
  • If the function fails to register a hook for the OS termination signals.

§Thread Communication Flow

The controlled shutdown sequence is visualized below:

graph LR signal_handler[Signal handler] --> messaging[Messaging] signal_handler --> refill[Refill control] refill --> signal_handler signal_handler --> tank_level_switch[Tank Level Switch] tank_level_switch --> signal_handler signal_handler --> heating[Heating control] heating --> signal_handler signal_handler --> relay_manager[Relay Manager] relay_manager --> signal_handler signal_handler --> atlas_scientific[Atlas Scientific] atlas_scientific --> signal_handler signal_handler --> ambient[Ambient] ambient --> signal_handler signal_handler --> data_logger[Data logger] data_logger --> signal_handler signal_handler --> balling[Balling dosing control] balling --> signal_handler signal_handler --> ventilation[Ventilation control] ventilation --> signal_handler signal_handler --> monitors[Monitors] monitors --> signal_handler signal_handler --> feed[Feed control] feed --> signal_handler schedule_check[ScheduleCheck] --> signal_handler signal_handler --> schedule_check signal_handler --> tcp_communication[TCP communication] tcp_communication --> signal_handler signal_handler --> dht[Dht] signal_handler --> i2c_interface[I2C interface] signal_handler --> watchdog[Watchdog] watchdog --> signal_handler