canic_core/ops/
service.rs

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