Skip to content

Commit

Permalink
feat: initialize dashboard module
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Ponsard <[email protected]>
  • Loading branch information
nponsard committed Jun 1, 2023
1 parent 0093f7e commit 64fc1a1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions aster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async fn main() -> Result<(), anyhow::Error> {
let mut services: Vec<Box<dyn AsterService>> = vec![
Box::<frontend_server::FrontendServer>::default(),
Box::<BillingService>::default(),
Box::<dashboard::DashboardServer>::default(),
];

info!("Init services");
Expand Down
7 changes: 7 additions & 0 deletions dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.71"
async-trait = "0.1.68"
axum = "0.6.18"
log = "0.4.18"
sqlx = { version = "0.6.3", features = ["runtime-tokio-native-tls", "postgres", "chrono" ] }
tokio = { version = "1.12.0", features = ["full"] }
common = { path = "../common" }
48 changes: 39 additions & 9 deletions dashboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
use anyhow::Context;
use async_trait::async_trait;
use axum::{Router, Server};
use common::{messaging::crossbeam::CrossbeamMessagingFactory, AsterService};
use sqlx::{postgres::PgPoolOptions, PgPool};
const SERVICE_PORT: u16 = 3036;

#[derive(Debug, Default)]
pub struct DashboardServer {
pool: Option<PgPool>,
}

#[cfg(test)]
mod tests {
use super::*;
#[async_trait]
impl AsterService for DashboardServer {
async fn init(
&mut self,
_messaging: &mut CrossbeamMessagingFactory,
) -> Result<(), anyhow::Error> {
// read the database url from the environment
let database_url = std::env::var("DATABASE_URL").context("DATABASE_URL not set")?;

// create a connection pool

self.pool = Some(
PgPoolOptions::new()
.max_connections(5)
.connect(database_url.as_str())
.await?,
);

Ok(())
}
async fn run(&mut self) -> Result<(), anyhow::Error> {
let router = Router::new();

// run the server

Server::bind(&format!("0.0.0.0:{}", SERVICE_PORT).parse().unwrap())
.serve(router.into_make_service())
.await?;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
Ok(())
}
}

0 comments on commit 64fc1a1

Please sign in to comment.