From 3f5b9345a08deb2e498b4748efe5edd4d8415d03 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 2 Oct 2026 17:22:41 +0200 Subject: [PATCH] feat(uploads): HasRoom -- say before spooling whether a submit would be accepted (second review) Co-Authored-By: Claude Sonnet 5.5 --- internal/uploads/worker.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/uploads/worker.go b/internal/uploads/worker.go index 591cab8..6da7b37 100644 --- a/internal/uploads/worker.go +++ b/internal/uploads/worker.go @@ -130,6 +130,24 @@ func NewWorker(s WorkerStore, c Converter, t Transcriber, tmpDir string, timeout return w } +// HasRoom reports whether a job from this user would be accepted right now. It lets the +// intake refuse BEFORE spooling up to the upload cap and running ffprobe; Submit still +// enforces the same limits atomically, so a race costs at worst one refused submit. +func (w *Worker) HasRoom(userID string) bool { + w.mu.Lock() + defer w.mu.Unlock() + if w.stopped || len(w.queue) >= w.maxQueued { + return false + } + mine := 0 + for _, q := range w.queue { + if q.UserID == userID { + mine++ + } + } + return mine < w.maxPerUser +} + // Submit queues a job. It never blocks. It satisfies Submitter. func (w *Worker) Submit(j Job) error { w.mu.Lock()