aboutsummaryrefslogtreecommitdiffstats
path: root/crates/daemon/src/components/history.rs
blob: b476f62754a6c9ec0a8b0681fe12397b6f20818a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! History component.
//!
//! Handles command history lifecycle (start/end) and provides the History gRPC service.

use crate::{
    aclient::{history::store::HistoryStore, settings::Settings},
    api::server::history::HistoryGrpcService,
};
use eyre::Result;

use crate::{
    daemon::{Component, DaemonHandle},
    events::DaemonEvent,
};

#[tonic::async_trait]
impl Component for HistoryGrpcService {
    fn name(&self) -> &'static str {
        "history"
    }

    async fn start(&mut self, handle: DaemonHandle) -> Result<()> {
        // Create the history store
        let host_id = Settings::host_id().await?;
        let history_store =
            HistoryStore::new(handle.store().clone(), host_id, *handle.encryption_key());

        *self.history_store.write().await = Some(history_store);
        *self.handle.write().await = Some(handle);

        tracing::info!("history component started");
        Ok(())
    }

    async fn handle_event(&mut self, _event: &DaemonEvent) -> Result<()> {
        // History component produces events but doesn't need to react to them
        Ok(())
    }

    async fn stop(&mut self) -> Result<()> {
        tracing::info!("history component stopped");
        Ok(())
    }
}