Module sql_interface_schedule

Source
Expand description

Contains functions for execution of all queries relevant for schedule (permission) Manages time-based scheduling for various application modules.

This module provides a dedicated interface, SqlInterfaceSchedule, for reading and interpreting time-based restrictions from the schedule table in the database. Its primary purpose is to allow users to inhibit certain activities that may cause noise or other disturbances (e.g., pumps for Balling or Refill) during specific times, such as at night.

§Key Components

  • SqlInterfaceSchedule: The main struct that holds a database connection, performs validation, and provides methods to read and query schedule data.

  • ScheduleEntry: A processed, type-safe representation of a single schedule rule. It converts raw string data from the database into strongly typed ScheduleType and chrono::NaiveTime fields.

  • ScheduleType: An enum that identifies the specific application module (e.g., Balling, Refill, Heating) that a schedule rule applies to.

§Design and Purpose

The module is designed to be a robust and centralized point for all scheduling logic.

  • Fail-Fast Validation: The new() constructor performs several “fail-fast” checks at startup. It verifies that the schedule table contains no NULL values and that the number of entries does not exceed a configured limit. This prevents the application from starting in an invalid state.

  • Data Processing and Caching: The read_schedule() method fetches all rules from the database, parses them into ScheduleEntry objects, and stores them in an internal cache (Vec). This is efficient as the database is only queried once.

  • Robust Error Handling: During processing, read_schedule() does not fail on the first malformed entry. Instead, it collects all parsing errors (e.g., for an invalid time string) and returns them in a Vec, allowing for comprehensive diagnostics of database integrity issues.

  • Time Window Logic: The ScheduleEntry::check_if_allowed() method provides a simple way to determine if the current system time falls within the active window of a given schedule.

Structs§

ScheduleEntry
Contains one schedule data set after post-processing
SqlInterfaceSchedule
Contains the configuration and the implementation of the SQL interface for Schedule.
SqlScheduleEntry
Contains one schedule data set as read from the database

Enums§

ScheduleType
List of all modules that are subject to limitations by schedule. Background: These activities cause noise - the user shall be able to inhibit these noises during nighttime.