feat(backend): implement graceful shutdown for container stop

Graceful shutdown ensures in-flight operations complete before process exits:
- Lifespan shutdown handler drains pending tasks with 25s timeout
- Scheduler stops accepting new jobs immediately
- HTTP session, external logging, scheduler lock, DB conn closed cleanly
- 25s Python timeout leaves 5s margin before Docker's 30s SIGKILL

Files changed:
- backend/app/main.py: enhanced _lifespan shutdown with task drain
- Docker/Dockerfile.backend: documented signal handling in header
- Docker/docker-compose.yml: added stop_grace_period: 30s
- Docker/compose.prod.yml: added stop_grace_period: 30s
- Docs/Deployment.md: new Graceful Shutdown section with sequence table
- Docs/TROUBLESHOOTING.md: new Graceful Shutdown Issues section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-02 22:47:10 +02:00
parent f6c3c02183
commit b631c1c546
10 changed files with 383 additions and 20 deletions

View File

@@ -7,7 +7,7 @@
import { api } from "./client";
import { ENDPOINTS } from "./endpoints";
import type { LoginResponse, LogoutResponse } from "../types/auth";
import type { LoginResponse, LogoutResponse, SessionValidResponse } from "../types/auth";
/**
* Authenticate with the master password.
@@ -38,6 +38,6 @@ export async function logout(): Promise<LogoutResponse> {
* @returns An object confirming the session is valid.
* @throws {ApiError} When the session is invalid or expired (401).
*/
export async function validateSession(signal?: AbortSignal): Promise<{ valid: boolean }> {
return api.get<{ valid: boolean }>(ENDPOINTS.authSession, signal);
export async function validateSession(signal?: AbortSignal): Promise<SessionValidResponse> {
return api.get<SessionValidResponse>(ENDPOINTS.authSession, signal);
}

View File

@@ -16,3 +16,8 @@ export interface LoginResponse {
export interface LogoutResponse {
message: string;
}
/** Response from GET /api/auth/session confirming session validity. */
export interface SessionValidResponse {
valid: boolean;
}