Skip to content

Overhaul core Tracker: extract stats #1184

@josecelano

Description

@josecelano

Parent issue: #1181

Extract the responsibility for handling stats (send events and return metrics) from the core tracker.

These two methods (get_stats and get_stats) will be called directly exposing the stats_repository and stats_event_sender.

    /// It return the `Tracker` [`statistics::metrics::Metrics`].
    ///
    /// # Context: Statistics
    pub async fn get_stats(&self) -> tokio::sync::RwLockReadGuard<'_, statistics::metrics::Metrics> {
        self.stats_repository.get_stats().await
    }

    /// It allows to send a statistic events which eventually will be used to update [`statistics::metrics::Metrics`].
    ///
    /// # Context: Statistics
    pub async fn get_stats(
        &self,
        event: statistics::event::Event,
    ) -> Option<Result<(), SendError<statistics::event::Event>>> {
        match &self.stats_event_sender {
            None => None,
            Some(stats_event_sender) => stats_event_sender.send_event(event).await,
        }
    }

See the previous similar refactor for reference.

Since I'm extracting a lot of code from the core Tracker now the app bootstrapping is becoming more complex because the tracker dependencies are built before instantiating the tracker. At some point I think I will create a IoC container to store all the references to services (Arc<...>).

cc @da2ce7

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions