Compare commits

..

3 commits

Author SHA1 Message Date
e3114beb9a bump deps 2025-06-04 14:46:07 +02:00
249c30f2da 2025-04-16 14:37:10 +02:00
9c8b39e98f Honor SIGTERM 2025-04-16 14:30:59 +02:00
3 changed files with 233 additions and 272 deletions

473
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
[package] [package]
name = "kosyncrs" name = "kosyncrs"
version = "2.1.1" version = "2.2.0"
edition = "2024" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -10,4 +10,4 @@ axum = "0.8.1"
serde = { version = "1.0.188", features = ["derive"] } serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107" serde_json = "1.0.107"
sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] } sqlx = { version = "0.8.3", features = ["runtime-tokio", "postgres"] }
tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.45.0", features = ["macros", "rt-multi-thread", "signal"] }

View file

@ -28,6 +28,7 @@ use axum::{
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::{Value, json}; use serde_json::{Value, json};
use sqlx::{PgExecutor, PgPool, postgres::PgPoolOptions}; use sqlx::{PgExecutor, PgPool, postgres::PgPoolOptions};
use tokio::signal;
use std::env; use std::env;
use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::time::{Duration, SystemTime, UNIX_EPOCH};
@ -88,17 +89,40 @@ async fn main() {
let mut bind_with = "0.0.0.0:".to_owned(); let mut bind_with = "0.0.0.0:".to_owned();
bind_with += &listen_port; bind_with += &listen_port;
let listener = tokio::net::TcpListener::bind(bind_with).await.unwrap(); let listener = tokio::net::TcpListener::bind(bind_with).await.unwrap();
axum::serve(listener, app).await.unwrap(); axum::serve(listener, app)
.with_graceful_shutdown(shutdown_signal())
.await
.unwrap();
} }
async fn root() -> &'static str { async fn root() -> &'static str {
"KOreader sync server" "KOReader sync server"
} }
async fn version() -> &'static str { async fn version() -> &'static str {
VERSION VERSION
} }
async fn shutdown_signal() {
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("Failed to install CTRL-C handler");
};
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("Failed to install Terminate handler")
.recv()
.await;
};
tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}
}
async fn create_user( async fn create_user(
State(db_pool): State<PgPool>, State(db_pool): State<PgPool>,
Json(payload): Json<User>, Json(payload): Json<User>,