46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use std::collections::HashMap;
|
|
|
|
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
use std::sync::{Arc, RwLock};
|
|
|
|
use reqwest::Client;
|
|
use tokio::sync::mpsc::Sender;
|
|
|
|
use crate::db::*;
|
|
use crate::docker::Docker;
|
|
use crate::docker::DockerLike;
|
|
use crate::settings::Settings;
|
|
|
|
use super::complaince::result::Result as CResult;
|
|
|
|
pub type ArcCtx = Arc<Ctx>;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Ctx {
|
|
pub settings: Settings,
|
|
pub db: Database,
|
|
pub client: Client,
|
|
pub results: Arc<RwLock<HashMap<String, Sender<CResult>>>>,
|
|
pub docker: Arc<dyn DockerLike>,
|
|
}
|
|
|
|
impl Ctx {
|
|
pub async fn new(settings: Settings) -> Self {
|
|
let results = HashMap::default();
|
|
let results = Arc::new(RwLock::new(results));
|
|
let client = Client::default();
|
|
let db = get_db(&settings).await;
|
|
Self {
|
|
settings,
|
|
client,
|
|
db,
|
|
results,
|
|
docker: Arc::new(Docker::new()),
|
|
}
|
|
}
|
|
}
|