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
use std::sync::Arc;
use std::sync::atomic::AtomicBool;

use async_trait::async_trait;
use http::Response;
use hyper::Body;

use crate::server::{ApiError, HttpRoute};

lazy_static! {
    pub static ref IN_ROTATION: AtomicBool = AtomicBool::new(true);
    pub static ref SHUTDOWN: AtomicBool = AtomicBool::new(false);
}

#[async_trait]
pub trait ServiceBuilder<T: Service, D: ServiceDaemon<T>>: Send + Sync {
    async fn build(self) -> anyhow::Result<(T, Option<D>)>;
}

#[async_trait]
pub trait Service: Send + Sync {
    async fn api_handler<'a>(
        &'a self,
        body: Body,
        route: &HttpRoute<'a>,
        path: &[&str],
    ) -> Result<Response<Body>, ApiError>;
}

#[async_trait]
pub trait ServiceDaemon<T>: Send + Sync
    where
        T: Service,
{
    async fn start(&self, service: Arc<T>);
}