-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nils Ponsard <[email protected]>
- Loading branch information
Showing
4 changed files
with
56 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |