cala_server/app/
mod.rs

1mod config;
2mod error;
3
4use sqlx::PgPool;
5
6use cala_ledger::CalaLedger;
7
8use crate::{integration::*, job::*};
9pub use config::*;
10pub use error::*;
11
12#[derive(Clone)]
13pub struct CalaApp {
14    pool: PgPool,
15    ledger: CalaLedger,
16    jobs: Jobs,
17}
18
19impl CalaApp {
20    pub(crate) async fn run(
21        pool: PgPool,
22        config: AppConfig,
23        ledger: CalaLedger,
24        registry: JobRegistry,
25    ) -> Result<Self, ApplicationError> {
26        let mut jobs = Jobs::new(&pool, config.job_execution, registry);
27        jobs.start_poll().await?;
28        Ok(Self { pool, ledger, jobs })
29    }
30
31    pub fn integrations(&self) -> Integrations {
32        Integrations::new(&self.pool)
33    }
34
35    pub fn ledger(&self) -> &CalaLedger {
36        &self.ledger
37    }
38
39    pub fn jobs(&self) -> &Jobs {
40        &self.jobs
41    }
42}