feat(uploads): HasRoom -- say before spooling whether a submit would be accepted (second review)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 17:22:41 +02:00
co-authored by Claude Sonnet 5.5
parent 16db156406
commit 3f5b9345a0
+18
View File
@@ -130,6 +130,24 @@ func NewWorker(s WorkerStore, c Converter, t Transcriber, tmpDir string, timeout
return w 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. // Submit queues a job. It never blocks. It satisfies Submitter.
func (w *Worker) Submit(j Job) error { func (w *Worker) Submit(j Job) error {
w.mu.Lock() w.mu.Lock()