docs(arch): reconcile deployment domain, staging volumes, and relocation invariants

- Update edge routing domain to roadtotech.me in overview and deployment specs
- Align Transmission container staging mount to /data/staging
- Document two-stage atomic relocation using /media/movies/.staging_<job_id>/ to prevent Jellyfin indexing races
- Formalize 15-minute stalled download timeout and Transmission session cleanup
- Add TMDB_API_KEY environment variable to deployment spec
This commit is contained in:
kiskaadee committed 2026-10-13 06:53:04 -05:00
1 parent bcc47f1e8e
commit 3954cadc54
3 files changed
+16 -9

No files matched your search

+10 -4
View File
@@ -62,8 +62,9 @@ stateDiagram-v2
### Transition & Failure Invariants ### Transition & Failure Invariants
1. **Linear Progression**: `QUEUED` ➔ `DOWNLOADING` ➔ `SCANNING` ➔ `VERIFYING_METADATA` ➔ `ORGANIZING` ➔ `COMPLETED`. 1. **Linear Progression**: `QUEUED` ➔ `DOWNLOADING` ➔ `SCANNING` ➔ `VERIFYING_METADATA` ➔ `ORGANIZING` ➔ `COMPLETED`.
2. **Terminal Failure**: Any failure at any phase transitions the job directly to `FAILED` with a populated `error_message`. 2. **Terminal Failure**: Any failure at any phase transitions the job directly to `FAILED` with a populated `error_message`.
3. **Crash & Restart Recovery**: Upon worker startup, any orphaned non-terminal jobs (`QUEUED`, `DOWNLOADING`, `SCANNING`, `VERIFYING_METADATA`, `ORGANIZING`) in the SQLite database are automatically transitioned to `FAILED` with reason `"Worker restarted during execution"`. Retrying requires a new submission. 3. **Stalled Download Timeout**: If a torrent achieves zero progress (0 bytes downloaded or unresolved magnet metadata) for 15 consecutive minutes, the job transitions to `FAILED` with reason `"Download stalled: no seeds or metadata timeout"`.
4. **Duplicate Rejection (Idempotency)**: 4. **Crash & Restart Recovery**: Upon worker startup, any orphaned non-terminal jobs (`QUEUED`, `DOWNLOADING`, `SCANNING`, `VERIFYING_METADATA`, `ORGANIZING`) in the SQLite database are automatically transitioned to `FAILED` with reason `"Worker restarted during execution"`. Retrying requires a new submission.
5. **Duplicate Rejection (Idempotency)**:
- A submission is rejected if a non-terminal job for the same `imdb_id` is currently active in the database. - A submission is rejected if a non-terminal job for the same `imdb_id` is currently active in the database.
- A submission is rejected if `/media/movies/*[imdbid-{imdb_id}]` already exists in the destination library. - A submission is rejected if `/media/movies/*[imdbid-{imdb_id}]` already exists in the destination library.
@@ -95,7 +96,7 @@ The sanitizer enforces a strict file-system boundary before files are touched or
--- ---
## 📂 Storage Paths & Naming Convention ## 📂 Storage Paths & Two-Stage Atomic Relocation
- **Canonical Staging Path**: `/data/staging/<job_id>/` - **Canonical Staging Path**: `/data/staging/<job_id>/`
- **Canonical Library Destination**: - **Canonical Library Destination**:
@@ -103,7 +104,12 @@ The sanitizer enforces a strict file-system boundary before files are touched or
/media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/<Title> (<Year>).<ext> /media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/<Title> (<Year>).<ext>
/media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/<Title> (<Year>).en.srt /media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/<Title> (<Year>).en.srt
``` ```
- **Cleanup**: The `/data/staging/<job_id>/` folder is purged immediately upon successful completion or terminal failure. - **Two-Stage Atomic Relocation (Cross-Volume Safe)**:
1. *Stage 1 (Transfer)*: Validated files are copied from `/data/staging/<job_id>/` to a temporary directory on the library mount: `/media/movies/.staging_<job_id>/` using `shutil.copy2`.
2. *Stage 2 (Atomic Swap)*: Once copying completes and file integrity is verified, `os.replace` atomically renames `/media/movies/.staging_<job_id>/` to the final `/media/movies/<Title> (<Year>) [imdbid-<IMDbID>]/` directory. This prevents Jellyfin/Plex from indexing partially-copied media.
- **Cleanup**:
- The scratch directory `/data/staging/<job_id>/` is purged immediately upon successful completion or terminal failure.
- The torrent session is removed from Transmission daemon via RPC `remove_torrent(id, delete_data=True)` to prevent lingering memory/network leaks.
--- ---
+4 -3
View File
@@ -24,7 +24,7 @@ services:
- magnetflix_internal - magnetflix_internal
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.magnetflix.rule=Host(`addmovie.arch-services.mywire.org`)" - "traefik.http.routers.magnetflix.rule=Host(`addmovie.roadtotech.me`)"
- "traefik.http.routers.magnetflix.entrypoints=websecure" - "traefik.http.routers.magnetflix.entrypoints=websecure"
- "traefik.http.routers.magnetflix.tls.certresolver=letsencrypt" - "traefik.http.routers.magnetflix.tls.certresolver=letsencrypt"
- "traefik.http.routers.magnetflix.middlewares=authelia@docker" - "traefik.http.routers.magnetflix.middlewares=authelia@docker"
@@ -42,6 +42,7 @@ services:
- DATABASE_URL=sqlite:////data/magnetflix.sqlite3 - DATABASE_URL=sqlite:////data/magnetflix.sqlite3
- STAGING_DIR=/data/staging - STAGING_DIR=/data/staging
- MEDIA_DIR=/media/movies - MEDIA_DIR=/media/movies
- TMDB_API_KEY=${TMDB_API_KEY}
volumes: volumes:
- ./data:/data - ./data:/data
- /mnt/storage/media/movies:/media/movies - /mnt/storage/media/movies:/media/movies
@@ -58,7 +59,7 @@ services:
- TZ=America/Chicago - TZ=America/Chicago
volumes: volumes:
- ./config/transmission:/config - ./config/transmission:/config
- ./data/staging:/downloads - ./data/staging:/data/staging
networks: networks:
- magnetflix_internal - magnetflix_internal
@@ -73,7 +74,7 @@ networks:
## 🔐 Authelia SSO Integration ## 🔐 Authelia SSO Integration
When a user visits `addmovie.arch-services.mywire.org`: When a user visits `addmovie.roadtotech.me`:
1. Traefik triggers the `authelia@docker` forward-auth middleware. 1. Traefik triggers the `authelia@docker` forward-auth middleware.
2. If unauthenticated, Authelia redirects the user to the login portal. 2. If unauthenticated, Authelia redirects the user to the login portal.
3. Upon authentication, Authelia injects headers into the forwarded request: 3. Upon authentication, Authelia injects headers into the forwarded request:
+2 -2
View File
@@ -31,14 +31,14 @@ sequenceDiagram
participant Engine as Transmission Daemon participant Engine as Transmission Daemon
participant Media as Jellyfin / Plex Library participant Media as Jellyfin / Plex Library
User->>Traefik: GET addmovie.arch-services.mywire.org User->>Traefik: GET addmovie.roadtotech.me
Traefik->>User: Renders MagNetFlix Web Form Traefik->>User: Renders MagNetFlix Web Form
User->>Traefik: Submit form (magnet URI + IMDb ID: tt1375666) User->>Traefik: Submit form (magnet URI + IMDb ID: tt1375666)
Traefik->>BFF: POST /api/v1/downloads (includes Remote-User header) Traefik->>BFF: POST /api/v1/downloads (includes Remote-User header)
BFF->>Worker: gRPC SubmitDownload(magnet, imdb_id, user) BFF->>Worker: gRPC SubmitDownload(magnet, imdb_id, user)
Worker-->>BFF: Acknowledged (Job ID: job-42) Worker-->>BFF: Acknowledged (Job ID: job-42)
BFF-->>User: Enqueued! Showing live progress BFF-->>User: Enqueued! Showing live progress
Worker->>Engine: Start torrent download in /tmp/staging/job-42 Worker->>Engine: Start torrent download in /data/staging/job-42
Engine-->>Worker: Download Completed Engine-->>Worker: Download Completed
Worker->>Worker: Run Security Whitelist Scan (Purge .exe/.bat) Worker->>Worker: Run Security Whitelist Scan (Purge .exe/.bat)
Worker->>Worker: Verify IMDb metadata & rename files Worker->>Worker: Verify IMDb metadata & rename files