use thiserror::Error;
use uuid::Uuid;
#[derive(Debug, Error)]
pub enum LifecycleError {
#[error("migration failed: {0}")]
MigrationFailed(String),
#[error("bootstrap failed: {0}")]
BootstrapFailed(String),
}
const DEFAULT_USER_ID_HEX: &str = "00000000000000000000000000000000";
pub async fn on_startup(_state: &crate::state::AppState) -> Result<(), LifecycleError> {
tracing::info!("Backend server has started");
Ok(())
}
pub fn default_user_id() -> Uuid {
Uuid::parse_str(DEFAULT_USER_ID_HEX).unwrap_or(Uuid::nil())
}
pub async fn on_shutdown(state: &crate::state::AppState) {
tracing::info!("Backend server is shutting down");
if let Err(e) = state.pipelines.shutdown().await {
tracing::warn!("pipeline registry shutdown failed (non-fatal): {e}");
} else {
tracing::info!("pipeline registry shutdown complete");
}
let aborted = state.sync.abort_all();
if !aborted.is_empty() {
tracing::info!(
"aborted {} in-flight cloud sync(s) on shutdown",
aborted.len()
);
}
}