All six test functions now have // TestFoo verifies... comments
matching the project's existing convention.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch from raw t.Errorf to testify/assert for consistency with the
rest of the codebase. Use t.Setenv() instead of manual os.Setenv/defer
os.Unsetenv for automatic cleanup. Simplify table structs where min
and max are always equal.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The QUEUE_WORKERS environment variable was defined and read in
getOptimalWorkerCount(), but NewTaskQueue() unconditionally overwrote
the result with the hardcoded legacyWorkers parameter (always 2).
This made QUEUE_WORKERS effectively dead code.
Now legacyWorkers is only used as a fallback when QUEUE_WORKERS is
not set, preserving the default of 2 workers while allowing users
to control concurrency via the environment variable.
Set QUEUE_WORKERS=1 to serialize all transcription jobs and prevent
system overload during bulk uploads.
Fixes: rishikanthc/Scriberr#379
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tests verifying that getOptimalWorkerCount() respects the
QUEUE_WORKERS environment variable and that NewTaskQueue() should
allow QUEUE_WORKERS to override the hardcoded legacy worker count.
Includes a failing test (TestNewTaskQueue_EnvOverridesLegacy) that
reproduces the bug where QUEUE_WORKERS is always overridden by the
hardcoded legacyWorkers parameter.
Ref: rishikanthc/Scriberr#379
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 5: Refactor queue.go (10 DB calls removed)
- Added JobRepository to TaskQueue struct and constructor
- Added UpdateStatus, UpdateError, FindByStatus, CountByStatus methods to JobRepository
- Replaced all database.DB calls with repository methods
Phase 6: Refactor chat_handlers.go and summarize_handlers.go (6 DB calls removed)
- Added GetMessageCountsBySessionIDs and GetLastMessagesBySessionIDs to ChatRepository
- Added UpdateSummary to JobRepository
- Replaced batch queries and update calls with repository methods
- Removed database import from both files
Phase 7: Refactor quick_transcription.go (3 DB calls removed)
- Added JobRepository injection to QuickTranscriptionService
- Updated constructor and all callers
Summary: 46+ database.DB calls replaced with repository methods across 7 phases.
All tests pass, build succeeds.
The jobScanner was running every 10 seconds and re-enqueueing jobs that
were already in the queue but hadn't started processing yet. This caused
completed files to be re-transcribed when auto-transcribe was enabled.
Changes:
- Removed jobScanner goroutine (10-second polling loop)
- Removed scanPendingJobs function
- Added recoverPendingJobs that runs ONCE at startup to recover
any pending jobs left from previous server runs
- Jobs are now only enqueued when explicitly requested:
- Upload with auto-transcribe enabled
- Manual transcription start
- Server restart recovery (one-time)