The TaskScheduler is a high-precision asynchronous task scheduling engine managing concurrent event execution, recurring sensor polling, and background collector tasks over a dedicated boost::asio::io_context thread (async_executor_thread_). It utilizes an executor_work_guard to maintain continuous event loop execution regardless of active task volume.
TaskSchedulerThe central orchestrator managing the dedicated execution thread and supervising active tasks via a thread-safe registry (id_to_async_tasks_).
TaskScheduler::OptionsDefines default operational thresholds:
cleanup_tasks_period: The interval for background eviction checks, defaulting to 10 seconds (kept at this duration to avoid overloading the scheduling loop).default_task_timeout: The maximum duration allowed before a task is considered unresponsive, defaulting to 60 seconds (aligning with standard client-side Redfish request timeouts).TaskWraps a single scheduled action's execution state around an underlying boost::asio::steady_timer.
Run(): Executes the assigned task payload and updates internal timestamps (last_run_time, wait_times).ScheduleNextRun(): Arms the steady_timer for the next iteration. It calculates expiration delay by deducting previous execution overhead (last_execution_duration_) from the base period.OnDone() (Task Completion & Acknowledgement): Periodic tasks require explicit invocation of the OnDone() acknowledgement callback upon completing their work. This signals execution termination, triggers the calculation of last_execution_duration_, and ensures the subsequent iteration is scheduled correctly to maintain precise periodicity.Cancel(): Flags the task as cancelled (cancelled_ = true) and aborts active timer operations.SetPeriod(): Cancels current waits and dynamically adjusts the scheduling interval (period_).TimeInfoCaptures granular timing diagnostics:
last_scheduled_time: Timestamp when the next execution was scheduled.last_run_time: Timestamp of the most recent execution completion.wait_times: A circular buffer logging historical execution latencies.ScheduleAsync(): Schedules a recurring task (TaskMode::kPeriodic) with an initial delay matching the target period (ExecutionMode::kRunAfterScheduling).RunAndScheduleAsync(): Triggers initial execution immediately (ExecutionMode::kRunImmediately), and then schedules subsequent recurring executions based on the period.ScheduleOneShotAsync(): Schedules a task to run exactly once (TaskMode::kOnce) after the specified delay. Its internal completion handler automatically invokes cancellation upon execution.CleanupInactiveTasks()Runs periodically to track execution timestamps exceeding task timeouts and purging dangling tasks. By comparing elapsed time since last_run_time against configured task timeouts, it evicts stalled operations (Cancel()).
GetSchedulingAccuracyPercentage()Evaluates timing precision by computing task lateness ratios:
average_wait_time against its assigned period.