canic_core/ops/
service.rs

1use crate::{
2    Error,
3    ops::{
4        OpsError,
5        model::memory::{
6            cycles::CycleTrackerOps, env::EnvOps, log::LogOps, reserve::CanisterReserveOps,
7        },
8    },
9};
10
11///
12/// TimerService
13/// Coordinates periodic background services (timers) for Canic canisters.
14///
15
16pub struct TimerService;
17
18impl TimerService {
19    /// Start timers that should run on all canisters.
20    pub fn start_all() -> Result<(), Error> {
21        // Ensure env is initialized (subnet type present) before starting timers.
22        EnvOps::try_get_subnet_type()?;
23
24        CycleTrackerOps::start();
25        LogOps::start_retention();
26
27        Ok(())
28    }
29
30    /// Start timers that should run only on root canisters.
31    pub fn start_all_root() -> Result<(), Error> {
32        OpsError::require_root()?;
33
34        // start shared timers too
35        Self::start_all()?;
36
37        // root-only services
38        CanisterReserveOps::start();
39
40        Ok(())
41    }
42}