aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-server/src/lib.rs
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2023-06-12 09:04:35 +0100
committerGitHub <noreply@github.com>2023-06-12 09:04:35 +0100
commit8655c93853506acf05f6ae4e58bfc2c6198be254 (patch)
tree22d20b35636ad2eb717d58c93ae07378adbb76eb /atuin-server/src/lib.rs
parentMake Ctrl-d behaviour match other tools (#1040) (diff)
downloadatuin-8655c93853506acf05f6ae4e58bfc2c6198be254.zip
refactor server to allow pluggable db and tracing (#1036)
* refactor server to allow pluggable db and tracing * clean up * fix descriptions * remove dependencies
Diffstat (limited to '')
-rw-r--r--atuin-server/src/lib.rs43
1 files changed, 18 insertions, 25 deletions
diff --git a/atuin-server/src/lib.rs b/atuin-server/src/lib.rs
index 01873af9..aa2250d3 100644
--- a/atuin-server/src/lib.rs
+++ b/atuin-server/src/lib.rs
@@ -2,45 +2,38 @@
use std::net::{IpAddr, SocketAddr};
+use atuin_server_database::Database;
use axum::Server;
-use database::Postgres;
use eyre::{Context, Result};
-use crate::settings::Settings;
+mod handlers;
+mod router;
+mod settings;
+mod utils;
+pub use settings::Settings;
use tokio::signal;
-pub mod auth;
-pub mod calendar;
-pub mod database;
-pub mod handlers;
-pub mod models;
-pub mod router;
-pub mod settings;
-pub mod utils;
-
async fn shutdown_signal() {
- let terminate = async {
- signal::unix::signal(signal::unix::SignalKind::terminate())
- .expect("failed to register signal handler")
- .recv()
- .await;
- };
-
- tokio::select! {
- _ = terminate => (),
- }
+ signal::unix::signal(signal::unix::SignalKind::terminate())
+ .expect("failed to register signal handler")
+ .recv()
+ .await;
eprintln!("Shutting down gracefully...");
}
-pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> {
+pub async fn launch<Db: Database>(
+ settings: Settings<Db::Settings>,
+ host: String,
+ port: u16,
+) -> Result<()> {
let host = host.parse::<IpAddr>()?;
- let postgres = Postgres::new(settings.clone())
+ let db = Db::new(&settings.db_settings)
.await
- .wrap_err_with(|| format!("failed to connect to db: {}", settings.db_uri))?;
+ .wrap_err_with(|| format!("failed to connect to db: {:?}", settings.db_settings))?;
- let r = router::router(postgres, settings);
+ let r = router::router(db, settings);
Server::bind(&SocketAddr::new(host, port))
.serve(r.into_make_service())