fix: resolve job-not-found race and YYMMDD scan folder structure
Race condition (worker "Job not found in DB"): - RedisJobQueue.enqueue() was pushing job IDs to Redis immediately after flush() but before the API transaction committed, so the worker would read an ID that didn't exist yet in the DB from its own session. - Fix: defer the Redis rpush until after session.commit() via a pending- push list drained by get_session() after each successful commit. - Worker: drain stale Redis queue entries on startup to clear any IDs left over from previously uncommitted transactions. - Worker: add 3-attempt retry with 200ms sleep when a job is not found, as a safety net for any remaining propagation edge cases. NC scan folder structure (YYMMDD rehearsal subfolders): - Previously used dir_name as song title for all files in a subdirectory, meaning every file got the folder name (e.g. "231015") as its title. - Fix: derive song title from Path(sub_rel).stem so each audio file gets its own name; use the file's parent path as nc_folder for version grouping. - Rehearsal folder name stored in song.notes as "Rehearsal: YYMMDD". - Added structured logging throughout the scan: entries found, per-folder file counts, skip/create/import decisions, and final summary count. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,10 +39,15 @@ def get_session_factory() -> async_sessionmaker[AsyncSession]:
|
||||
|
||||
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
"""FastAPI dependency that yields an async DB session."""
|
||||
from rehearsalhub.queue.redis_queue import flush_pending_pushes
|
||||
|
||||
async with get_session_factory()() as session:
|
||||
try:
|
||||
yield session
|
||||
await session.commit()
|
||||
# Fire any deferred Redis pushes AFTER commit so the worker always
|
||||
# finds the job row already committed in the DB.
|
||||
await flush_pending_pushes(session)
|
||||
except Exception:
|
||||
await session.rollback()
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user