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()