Compare commits
2 Commits
96cd918dfe
...
2e3d6999ff
Author | SHA1 | Date |
---|---|---|
Aravinth Manivannan | 2e3d6999ff | |
Aravinth Manivannan | 45a5d5ce9f |
2
build.rs
2
build.rs
|
@ -21,7 +21,7 @@ use sqlx::types::time::OffsetDateTime;
|
|||
fn main() {
|
||||
// note: add error checking yourself.
|
||||
let output = Command::new("git")
|
||||
.args(&["rev-parse", "HEAD"])
|
||||
.args(["rev-parse", "HEAD"])
|
||||
.output()
|
||||
.unwrap();
|
||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
|
|
|
@ -8,4 +8,13 @@ edition = "2021"
|
|||
[dependencies]
|
||||
serde = { version = "1", features=["derive"]}
|
||||
serde_json = { version ="1", features = ["raw_value"]}
|
||||
async-trait = "0.1.57"
|
||||
async-trait = { version = "0.1.57", optional = true}
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"min",
|
||||
"full",
|
||||
]
|
||||
|
||||
full = ["async-trait", "min"]
|
||||
min = []
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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 crate::event_types::EventType;
|
||||
use async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Conductor: std::marker::Send + std::marker::Sync + CloneConductor {
|
||||
async fn process(&self, event: EventType);
|
||||
async fn health(&self) -> bool;
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// Trait to clone Conductor
|
||||
pub trait CloneConductor {
|
||||
/// clone DB
|
||||
fn clone_conductor(&self) -> Box<dyn Conductor>;
|
||||
}
|
||||
|
||||
impl<T> CloneConductor for T
|
||||
where
|
||||
T: Conductor + Clone + 'static,
|
||||
{
|
||||
fn clone_conductor(&self) -> Box<dyn Conductor> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<dyn Conductor> {
|
||||
fn clone(&self) -> Self {
|
||||
(**self).clone_conductor()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TestConductor;
|
||||
|
||||
const TEST_CONDUCTOR_NAME: &str = "TEST_CONDUCTOR";
|
||||
|
||||
#[async_trait]
|
||||
impl Conductor for TestConductor {
|
||||
async fn process(&self, _event: EventType) {}
|
||||
fn name(&self) -> &'static str {
|
||||
TEST_CONDUCTOR_NAME
|
||||
}
|
||||
async fn health(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_good() {
|
||||
let c = TestConductor {};
|
||||
assert_eq!(c.name(), TEST_CONDUCTOR_NAME);
|
||||
assert!(c.health().await);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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 serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
||||
#[serde(untagged)]
|
||||
pub enum EventType {
|
||||
NewHostname(String),
|
||||
}
|
|
@ -14,67 +14,13 @@
|
|||
* 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 async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
||||
#[serde(untagged)]
|
||||
pub enum EventType {
|
||||
NewHostname(String),
|
||||
}
|
||||
#[cfg(feature = "min")]
|
||||
pub mod event_types;
|
||||
#[cfg(feature = "min")]
|
||||
pub use event_types::*;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Conductor: std::marker::Send + std::marker::Sync + CloneConductor {
|
||||
async fn process(&self, event: EventType);
|
||||
async fn health(&self) -> bool;
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// Trait to clone Conductor
|
||||
pub trait CloneConductor {
|
||||
/// clone DB
|
||||
fn clone_conductor(&self) -> Box<dyn Conductor>;
|
||||
}
|
||||
|
||||
impl<T> CloneConductor for T
|
||||
where
|
||||
T: Conductor + Clone + 'static,
|
||||
{
|
||||
fn clone_conductor(&self) -> Box<dyn Conductor> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<dyn Conductor> {
|
||||
fn clone(&self) -> Self {
|
||||
(**self).clone_conductor()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct TestConductor;
|
||||
|
||||
const TEST_CONDUCTOR_NAME: &str = "TEST_CONDUCTOR";
|
||||
|
||||
#[async_trait]
|
||||
impl Conductor for TestConductor {
|
||||
async fn process(&self, _event: EventType) {}
|
||||
fn name(&self) -> &'static str {
|
||||
TEST_CONDUCTOR_NAME
|
||||
}
|
||||
async fn health(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_good() {
|
||||
let c = TestConductor {};
|
||||
assert_eq!(c.name(), TEST_CONDUCTOR_NAME);
|
||||
assert!(c.health().await);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "full")]
|
||||
pub mod conductor;
|
||||
#[cfg(feature = "full")]
|
||||
pub use conductor::*;
|
||||
|
|
|
@ -18,8 +18,6 @@ use actix_web::{web, HttpResponse, Responder};
|
|||
use derive_builder::Builder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use libconductor::Conductor;
|
||||
|
||||
use crate::AppCtx;
|
||||
use crate::{GIT_COMMIT_HASH, VERSION};
|
||||
|
||||
|
|
|
@ -14,12 +14,10 @@
|
|||
* 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::collections::HashMap;
|
||||
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use libconductor::{Conductor, EventType};
|
||||
use libconductor::EventType;
|
||||
|
||||
use crate::errors::*;
|
||||
use crate::AppCtx;
|
||||
|
|
Loading…
Reference in New Issue