ftest/src/ctx.rs

56 lines
1.6 KiB
Rust

use std::collections::HashMap;
/*
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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()),
}
}
}