WAGERBABE DOCS
All Stories
2-1-10-props-cache-warming-background-refreshDoneEpic 2.1

Story 2.1.10: Props Cache Warming & Background Refresh

Status: done

Tasks

  • Task 1: Create PropsCache WarmingService (AC: #1, #2, #3)
    • 1.1: Create `server/app/services/props_cache_warmer.py` service class
    • 1.2: Implement `get_upcoming_fixtures(hours_ahead=1)` to find games starting within 1 hour
    • 1.3: Implement `warm_prop_categories(fixture_id)` - fetch and cache prop categories
    • 1.4: Implement `warm_popular_props(fixture_id)` - fetch and cache top player props
    • 1.5: Add logging for each warm operation (fixture_id, cache_key, duration_ms)
  • Task 2: Implement APScheduler background job (AC: #3)
    • 2.1: Register cache warmer job in `server/app/main.py` startup event
    • 2.2: Configure job to run every 5 minutes with `asyncio.create_task`
    • 2.3: Add job locking to prevent overlapping runs (Redis-based lock via `set_with_lock`)
    • 2.4: Implement graceful shutdown handling for scheduler
    • 2.5: Add error handling with logging for failed warm operations
  • Task 3: Implement priority queue for high-profile games (AC: #4)
    • 3.1: Define priority scoring: primetime slots (7-10 PM EST), weekend games, NFL/NBA
    • 3.2: Create `calculate_priority(fixture)` function to compute priority score
    • 3.3: Process high-priority fixtures first, lower priority if time permits
    • 3.4: Add priority score to logging for observability
  • Task 4: Integrate with existing Redis cache infrastructure (AC: #1, #2, #7)
    • 4.1: Use existing cache key patterns: `props:categories:{fixture_id}` (10 min TTL)
    • 4.2: Use existing cache key patterns: `props:{fixture_id}:{category}:{sportsbook}` (2 min TTL)
    • 4.3: Use `set_with_lock` for SWR pattern to prevent cache stampede
    • 4.4: Verify cache keys align with props.py endpoint consumer patterns
  • Task 5: Add health check and monitoring (AC: #5, #6)
    • 5.1: Extend `/health/cache/props` endpoint with warmer status
    • 5.2: Track `last_run_at`, `fixtures_warmed`, `categories_cached`, `props_cached`
    • 5.3: Add `get_warmer_status()` for observability
    • 5.4: Create health endpoint: `GET /health/cache/props`
    • 5.5: Set up status thresholds: >5 errors triggers degraded status
  • Task 6: Testing and validation (AC: #5)
    • 6.1: Validated import functionality for `PropsCacheWarmer` service methods
    • 6.2: Validated main.py startup/shutdown integration
    • 6.3: Validated health endpoint registration
    • 6.4: Load test: verify prop builder response times during cache warm vs cold (deferred)
    • 6.5: Document cache warming behavior in runbook (deferred)

Progress

Tasks6/6
Acceptance Criteria0
Total Tasks6