Files
Jellymove/crates/jm-server/src/lib.rs
T
IxianPixel 25a743b350
CI / test (push) Successful in 1m12s
Show folder sizes for movies, shows and seasons. Closes #5
The library lists now show how much space each movie and show takes on disk, counting everything a move copies, with a per-season breakdown for shows, a running total and a "Largest first" sort.

- sizes.rs: a single background worker measures one folder at a time. Listing returns cached sizes straight away and queues folders; the UI
  polls until every size has arrived.
- Cached in a new folder_sizes table (store migration v2). A size is kept while the folder's signature (mtimes of the folder and its direct
  subfolders) is unchanged, checked at most hourly and re-measured after 7 days.
- Each agent measures its own folders, so peer listings carry the peer's sizes.
- Tests for measuring, signatures, natural season order, the migration, and an e2e test covering both sides and a moved item.
2026-11-06 16:43:52 +00:00

61 lines
1.8 KiB
Rust

//! The jellymove daemon: HTTP API, embedded UI, job runner and source exports.
pub mod api;
pub mod config;
pub mod export;
pub mod library;
pub mod peer;
pub mod runner;
pub mod sizes;
pub mod state;
pub mod trash;
pub mod ui;
use std::sync::Arc;
pub use config::Config;
use tower_http::trace::TraceLayer;
/// Open state, resume interrupted jobs and serve until shutdown.
pub async fn run(cfg: Config) -> anyhow::Result<()> {
std::fs::create_dir_all(&cfg.data_dir)?;
let store = jm_store::Store::open(&cfg.data_dir.join("jellymove.db"))?;
let listen = cfg.listen;
let state = Arc::new(state::AppState::new(cfg, store)?);
match state.jellyfin.system_info().await {
Ok(i) => {
tracing::info!(server = %i.server_name, version = %i.version, "connected to Jellyfin")
}
Err(e) => {
tracing::warn!(error = %e, "can't reach Jellyfin yet; will keep trying on demand")
}
}
runner::resume_all(&state).await?;
let app = api::router(state.clone()).layer(TraceLayer::new_for_http());
let listener = tokio::net::TcpListener::bind(listen).await?;
tracing::info!(%listen, node = %state.cfg.node_name, "jellymove listening");
axum::serve(listener, app)
.with_graceful_shutdown(shutdown_signal())
.await?;
Ok(())
}
async fn shutdown_signal() {
let ctrl_c = async {
let _ = tokio::signal::ctrl_c().await;
};
#[cfg(unix)]
let term = async {
if let Ok(mut s) = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
{
s.recv().await;
}
};
#[cfg(not(unix))]
let term = std::future::pending::<()>();
tokio::select! { _ = ctrl_c => {}, _ = term => {} }
tracing::info!("shutting down; in-flight transfers will resume on next start");
}