MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / spawn_flush_task

Function spawn_flush_task

nodedb/src/control/security/metering/counter.rs:124–141  ·  view source on GitHub ↗

Spawn the periodic usage flush task.

(
    counter: std::sync::Arc<UsageCounter>,
    store: std::sync::Arc<super::store::UsageStore>,
    interval_secs: u64,
)

Source from the content-addressed store, hash-verified

122
123/// Spawn the periodic usage flush task.
124pub fn spawn_flush_task(
125 counter: std::sync::Arc<UsageCounter>,
126 store: std::sync::Arc<super::store::UsageStore>,
127 interval_secs: u64,
128) -> tokio::task::JoinHandle<()> {
129 tokio::spawn(async move {
130 let mut ticker =
131 tokio::time::interval(std::time::Duration::from_secs(interval_secs.max(10)));
132 ticker.tick().await; // Skip first immediate tick.
133 loop {
134 ticker.tick().await;
135 let events = counter.drain();
136 if !events.is_empty() {
137 store.ingest(events);
138 }
139 }
140 })
141}
142
143#[cfg(test)]
144mod tests {

Callers 1

spawn_background_loopsFunction · 0.85

Calls 5

ingestMethod · 0.80
spawnFunction · 0.50
tickMethod · 0.45
drainMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected