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>
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
// Package storage keeps downloaded files. Backends are chosen by
|
|
// configuration and share one interface.
|
|
package storage
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// ErrNotFound is returned when a key does not exist.
|
|
var ErrNotFound = errors.New("storage: not found")
|
|
|
|
// Object describes a stored file.
|
|
type Object struct {
|
|
Key string
|
|
Size int64
|
|
ModTime time.Time
|
|
}
|
|
|
|
// Storage is a flat key to file store. Keys use forward slashes and never
|
|
// start with one, for example "jobs/01abc/media.mp4".
|
|
type Storage interface {
|
|
// Put stores r under key, replacing any previous content. size may be -1
|
|
// when unknown.
|
|
Put(ctx context.Context, key string, r io.Reader, size int64) error
|
|
// Open returns a reader for key and the size in bytes.
|
|
Open(ctx context.Context, key string) (io.ReadCloser, int64, error)
|
|
// Stat returns the object details without reading it.
|
|
Stat(ctx context.Context, key string) (Object, error)
|
|
// Delete removes key. Deleting a missing key is not an error.
|
|
Delete(ctx context.Context, key string) error
|
|
// List calls fn for every object whose key starts with prefix.
|
|
List(ctx context.Context, prefix string, fn func(Object) error) error
|
|
}
|
|
|
|
// Presigner is implemented by backends that can hand out time-limited
|
|
// URLs, so a worker or a browser can move file bytes directly to and from
|
|
// storage without passing through the core.
|
|
type Presigner interface {
|
|
// PresignPut returns a URL that accepts one HTTP PUT of the object.
|
|
PresignPut(ctx context.Context, key string, ttl time.Duration) (string, error)
|
|
// PresignGet returns a URL that serves the object to HTTP GET.
|
|
PresignGet(ctx context.Context, key string, ttl time.Duration) (string, error)
|
|
}
|