Phase 4: scale out

Remote workers, Postgres and S3, all chosen by configuration.

- Pull-based worker protocol over HTTP: claim (long poll), heartbeat,
  complete, fail, upload, source, probe. Workers need no inbound ports
- cmd/worker: standalone stateless worker with health endpoint and
  scheduled yt-dlp self-update
- Per-worker bearer tokens, stored hashed, revocable; identity always
  taken from the token; actions only on jobs the worker holds a lease for
- Tags: site_tags routes a site's jobs and lookups to workers that carry
  the required tags
- Drain, /workers, /ytdlp update, and "core worker add|revoke|list"
- Link lookups can run on remote workers (PROBE_MODE), so the core needs
  no yt-dlp and no residential address
- Postgres backend with pgx, same schema and queries; per-user advisory
  lock and job row lock where SQLite's serial writes were relied on
- The whole test suite runs on SQLite and on Postgres
- S3 storage backend with presigned worker uploads, sharing a conformance
  suite with the local backend
- Dockerfile with core, worker and faketelegram targets, docker-compose
  with optional Postgres and local Bot API server, systemd units
- deploy/acceptance/kill-worker.sh: kills a worker mid-job and checks
  that the other one delivers the file
- Fixes found on the way: /cancel could let the next playlist item start;
  a refund note could be missing when the sweep refunded first

Docker was not available on the build machine: the compose files were
validated with "docker compose config" only. The acceptance scenario was
run with real processes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 09:27:11 +00:00
co-authored by Claude Fable 5.2
parent 9c9d641eda
commit 7d4893bc3f
51 changed files with 4732 additions and 108 deletions
+20
View File
@@ -9,6 +9,9 @@ owners = []
# Public HTTPS base URL of this server, without a trailing slash.
public_url = ""
# Who looks links up for the card: "auto", "local" or "worker".
probe_mode = "auto"
[telegram]
api_url = "https://api.telegram.org"
mode = "polling" # polling or webhook
@@ -27,8 +30,25 @@ dsn = "data/dlbot.db"
backend = "local" # local or s3
local_dir = "data/files"
# Only for backend = "s3". Put the keys in S3_ACCESS_KEY and S3_SECRET_KEY
# in the environment, not here.
[storage.s3]
endpoint = ""
bucket = ""
region = "garage"
use_ssl = true
path_style = true # Garage and MinIO: true. AWS: false.
prefix = ""
presign = true # workers upload straight to the bucket
presign_endpoint = ""
# Which worker tags a site requires. A host covers its subdomains.
# [site_tags]
# "youtube.com" = ["residential"]
[worker]
embedded = true
tags = [] # tags of the embedded worker
concurrency = 2
temp_dir = "data/tmp"
ytdlp_path = "yt-dlp"