canic_core/ops/
mod.rs

1//! Operations layer.
2//!
3//! Ops functions are fallible and must not trap.
4//! All unrecoverable failures are handled at lifecycle boundaries.
5//!
6//! This module contains two kinds of operations:
7//!
8//! 1. **Control ops**
9//!    - Mutate state
10//!    - Perform orchestration
11//!    - Call IC management APIs
12//!    - Must be invoked via workflow
13//!
14//! 2. **View ops**
15//!    - Read-only facades over internal state
16//!    - Perform snapshotting, aggregation, pagination
17//!    - Safe to call directly from query endpoints
18//!
19//! Examples of view ops include registry exports and metrics views.
20
21pub(crate) mod adapter;
22pub mod config;
23pub mod ic;
24pub mod icrc;
25pub mod perf;
26pub mod rpc;
27pub mod runtime;
28pub mod storage;
29pub mod view;
30
31use std::time::Duration;
32
33///
34/// Constants
35///
36
37/// Shared initial delay for ops timers to allow init work to settle.
38pub const OPS_INIT_DELAY: Duration = Duration::from_secs(10);
39
40/// Shared cadence for cycle tracking (10 minutes).
41pub const OPS_CYCLE_TRACK_INTERVAL: Duration = Duration::from_secs(60 * 10);
42
43/// Shared cadence for log retention (10 minutes).
44pub const OPS_LOG_RETENTION_INTERVAL: Duration = Duration::from_secs(60 * 10);
45
46/// Pool timer initial delay (30 seconds) before first check.
47pub const OPS_POOL_INIT_DELAY: Duration = Duration::from_secs(30);
48
49/// Pool check cadence (30 minutes).
50pub const OPS_POOL_CHECK_INTERVAL: Duration = Duration::from_secs(30 * 60);
51
52///
53/// Prelude
54///
55
56/// Common imports for ops submodules and consumers.
57pub mod prelude {
58    pub use crate::{
59        cdk::{
60            api::{canister_self, msg_caller},
61            candid::CandidType,
62            types::{Account, Cycles, Int, Nat, Principal, Subaccount},
63        },
64        ids::CanisterRole,
65        log,
66        log::Level,
67        ops::OpsError,
68        ops::ic::{call::Call, call_and_decode},
69    };
70    pub use serde::{Deserialize, Serialize};
71}
72
73use crate::ThisError;
74
75///
76/// OpsError
77/// Error envelope shared across operations submodules
78///
79
80#[derive(Debug, ThisError)]
81pub enum OpsError {
82    #[error(transparent)]
83    ConfigOpsError(#[from] config::ConfigOpsError),
84
85    #[error(transparent)]
86    RpcOpsError(#[from] rpc::RpcOpsError),
87
88    #[error(transparent)]
89    RuntimeOpsError(#[from] runtime::RuntimeOpsError),
90
91    #[error(transparent)]
92    StorageOpsError(#[from] storage::StorageOpsError),
93}