Files
LEDMatrix/docs/archive/BACKGROUND_SERVICE_README.md
Chuck ddd300a117 Docs/consolidate documentation (#217)
* docs: rename FONT_MANAGER_USAGE.md to FONT_MANAGER.md

Renamed for clearer naming convention.
Part of documentation consolidation effort.

* docs: consolidate Plugin Store guides (2→1)

Merged:
- PLUGIN_STORE_USER_GUIDE.md
- PLUGIN_STORE_QUICK_REFERENCE.md

Into: PLUGIN_STORE_GUIDE.md

- Unified writing style to professional technical
- Added Quick Reference section at top for easy access
- Removed duplicate content
- Added cross-references to related documentation
- Updated formatting to match style guidelines

* docs: create user-focused Web Interface Guide

Created WEB_INTERFACE_GUIDE.md consolidating:
- V3_INTERFACE_README.md (technical details)
- User-facing interface documentation

- Focused on end-user tasks and navigation
- Removed technical implementation details
- Added common tasks section
- Included troubleshooting
- Professional technical writing style

* docs: consolidate WiFi setup guides (4→1)

Merged:
- WIFI_SETUP.md
- OPTIMAL_WIFI_AP_FAILOVER_SETUP.md
- AP_MODE_MANUAL_ENABLE.md
- WIFI_ETHERNET_AP_MODE_FIX.md (behavior documentation)

Into: WIFI_NETWORK_SETUP.md

- Comprehensive coverage of WiFi setup and configuration
- Clear explanation of AP mode failover and grace period
- Configuration scenarios and best practices
- Troubleshooting section combining all sources
- Professional technical writing style
- Added quick reference table for behavior

* docs: consolidate troubleshooting guides (4→1)

Merged:
- TROUBLESHOOTING_QUICK_START.md
- WEB_INTERFACE_TROUBLESHOOTING.md
- CAPTIVE_PORTAL_TROUBLESHOOTING.md
- WEATHER_TROUBLESHOOTING.md

Into: TROUBLESHOOTING.md

- Organized by issue category (web, WiFi, plugins)
- Comprehensive diagnostic commands reference
- Quick diagnosis steps at the top
- Service file template preserved
- Complete diagnostic script included
- Professional technical writing style

* docs: create consolidated Advanced Features guide

Merged:
- VEGAS_SCROLL_MODE.md
- ON_DEMAND_DISPLAY_QUICK_START.md
- ON_DEMAND_DISPLAY_API.md
- ON_DEMAND_CACHE_MANAGEMENT.md
- BACKGROUND_SERVICE_README.md
- PERMISSION_MANAGEMENT_GUIDE.md

Into: ADVANCED_FEATURES.md

- Comprehensive guide covering all advanced features
- Vegas scroll mode with integration examples
- On-demand display with API reference
- Cache management troubleshooting
- Background service documentation
- Permission management patterns
- Professional technical writing style

* docs: create Getting Started guide for first-time users

Created GETTING_STARTED.md:
- Quick start guide (5 minutes)
- Initial configuration walkthrough
- Common first-time issues and solutions
- Next steps and quick reference
- User-friendly tone for beginners
- Links to detailed documentation

* docs: archive consolidated source files and ephemeral docs

Archived files that have been consolidated:
- Plugin Store guides (2 files → PLUGIN_STORE_GUIDE.md)
- Web Interface guide (V3_INTERFACE_README.md → WEB_INTERFACE_GUIDE.md)
- WiFi Setup guides (4 files → WIFI_NETWORK_SETUP.md)
- Troubleshooting guides (4 files → TROUBLESHOOTING.md)
- Advanced Features (6 files → ADVANCED_FEATURES.md)

Archived ephemeral/debug documentation:
- DEBUG_WEB_ISSUE.md
- BROWSER_ERRORS_EXPLANATION.md
- FORM_VALIDATION_FIXES.md
- WEB_UI_RELIABILITY_IMPROVEMENTS.md
- CAPTIVE_PORTAL_TESTING.md
- NEXT_STEPS_COMMANDS.md
- STATIC_IMAGE_MULTI_UPLOAD_PLAN.md
- RECONNECT_AFTER_CAPTIVE_PORTAL_TESTING.md

Archived implementation summaries:
- PLUGIN_CONFIG_TABS_SUMMARY.md
- PLUGIN_CONFIG_SYSTEM_VERIFICATION.md
- PLUGIN_SCHEMA_AUDIT_SUMMARY.md
- STARTUP_OPTIMIZATION_SUMMARY.md
- PLUGIN_DISPATCH_IMPLEMENTATION.md
- NESTED_SCHEMA_IMPLEMENTATION.md
- AP_MODE_MANUAL_ENABLE_CHANGES.md
- PLUGIN_CONFIG_SYSTEM_EXPLANATION.md

Total archived: 27 files
Preserves git history while cleaning up main docs directory

* docs: rename API_REFERENCE.md to REST_API_REFERENCE.md

Renamed for clarity - this is specifically the REST API reference
for the web interface, not a general API reference.

* docs: update README.md to reflect consolidated documentation structure

Updated documentation index:
- Reflects new consolidated guides (51 → 16-17 files)
- Updated Quick Start sections with new file names
- Added consolidation history (January 2026)
- Updated file references (API_REFERENCE → REST_API_REFERENCE)
- Documented archival of 33 files
- Added benefits of consolidation
- Updated statistics and highlights
- Removed outdated references
- Professional writing style maintained throughout

* docs: add Vegas scroll mode system architecture documentation

Added comprehensive internal architecture section for Vegas mode:
- Component overview with diagram
- VegasModeCoordinator responsibilities and main loop
- StreamManager buffering strategy and content flow
- PluginAdapter integration and fallback behavior
- RenderPipeline 125 FPS rendering process
- Component interaction flows
- Thread safety patterns
- Performance characteristics

Covers:
- How the four components work together
- Initialization and render loop flows
- Config update handling
- Frame rate management and optimization
- Memory usage and CPU characteristics

---------

Co-authored-by: Chuck <chuck@example.com>
2026-01-29 10:32:00 -05:00

6.1 KiB

Background Data Service for LEDMatrix

Overview

The Background Data Service is a new feature that implements background threading for season data fetching to prevent blocking the main display loop. This significantly improves responsiveness and user experience during data fetching operations.

Key Benefits

  • Non-blocking: Season data fetching no longer blocks the main display loop
  • Immediate Response: Returns cached or partial data immediately while fetching complete data in background
  • Configurable: Can be enabled/disabled per sport with customizable settings
  • Thread-safe: Uses proper synchronization for concurrent access
  • Retry Logic: Automatic retry with exponential backoff for failed requests
  • Progress Tracking: Comprehensive logging and statistics

Architecture

Core Components

  1. BackgroundDataService: Main service class managing background threads
  2. FetchRequest: Represents individual fetch operations
  3. FetchResult: Contains results of fetch operations
  4. Sport Managers: Updated to use background service

How It Works

  1. Cache Check: First checks for cached data and returns immediately if available
  2. Background Fetch: If no cache, starts background thread to fetch complete season data
  3. Partial Data: Returns immediate partial data (current/recent games) for quick display
  4. Completion: Background fetch completes and caches full dataset
  5. Future Requests: Subsequent requests use cached data for instant response

Configuration

NFL Configuration Example

{
    "nfl_scoreboard": {
        "enabled": true,
        "background_service": {
            "enabled": true,
            "max_workers": 3,
            "request_timeout": 30,
            "max_retries": 3,
            "priority": 2
        }
    }
}

Configuration Options

  • enabled: Enable/disable background service (default: true)
  • max_workers: Maximum number of background threads (default: 3)
  • request_timeout: HTTP request timeout in seconds (default: 30)
  • max_retries: Maximum retry attempts for failed requests (default: 3)
  • priority: Request priority (higher = more important, default: 2)

Implementation Status

Phase 1: Background Season Data Fetching COMPLETED

  • Created BackgroundDataService class
  • Implemented thread-safe data caching
  • Added retry logic with exponential backoff
  • Modified NFL manager to use background service
  • Added configuration support
  • Created test script

Phase 2: Rollout to Other Sports (Next Steps)

  • Apply to NCAAFB manager
  • Apply to NBA manager
  • Apply to NHL manager
  • Apply to MLB manager
  • Apply to other sport managers

Testing

Test Script

Run the test script to verify background service functionality:

python test_background_service.py

Test Scenarios

  1. Cache Hit: Verify immediate return of cached data
  2. Background Fetch: Verify non-blocking background data fetching
  3. Partial Data: Verify immediate return of partial data during background fetch
  4. Completion: Verify background fetch completion and caching
  5. Subsequent Requests: Verify cache usage for subsequent requests
  6. Service Disabled: Verify fallback to synchronous fetching

Expected Results

  • Initial fetch should return partial data immediately (< 1 second)
  • Background fetch should complete within 10-30 seconds
  • Subsequent fetches should use cache (< 0.1 seconds)
  • No blocking of main display loop

Performance Impact

Before Background Service

  • Season data fetch: 10-30 seconds (blocking)
  • Display loop: Frozen during fetch
  • User experience: Poor responsiveness

After Background Service

  • Initial response: < 1 second (partial data)
  • Background fetch: 10-30 seconds (non-blocking)
  • Display loop: Continues normally
  • User experience: Excellent responsiveness

Monitoring

Logs

The service provides comprehensive logging:

[NFL] Background service enabled with 3 workers
[NFL] Starting background fetch for 2024 season schedule...
[NFL] Using 15 immediate events while background fetch completes
[NFL] Background fetch completed for 2024: 256 events

Statistics

Access service statistics:

stats = background_service.get_statistics()
print(f"Total requests: {stats['total_requests']}")
print(f"Cache hits: {stats['cached_hits']}")
print(f"Average fetch time: {stats['average_fetch_time']:.2f}s")

Error Handling

Automatic Retry

  • Failed requests are automatically retried with exponential backoff
  • Maximum retry attempts are configurable
  • Failed requests are logged with error details

Fallback Behavior

  • If background service is disabled, falls back to synchronous fetching
  • If background fetch fails, returns partial data if available
  • Graceful degradation ensures system continues to function

Future Enhancements

Phase 2 Features

  • Apply to all sport managers
  • Priority-based request queuing
  • Dynamic worker scaling
  • Request batching for efficiency

Phase 3 Features

  • Real-time data streaming
  • WebSocket support for live updates
  • Advanced caching strategies
  • Performance analytics dashboard

Troubleshooting

Common Issues

  1. Background service not starting

    • Check configuration: background_service.enabled = true
    • Verify cache manager is properly initialized
    • Check logs for initialization errors
  2. Slow background fetches

    • Increase request_timeout in configuration
    • Check network connectivity
    • Monitor API rate limits
  3. Memory usage

    • Background service automatically cleans up old requests
    • Adjust max_workers if needed
    • Monitor cache size

Debug Mode

Enable debug logging for detailed information:

logging.getLogger('src.background_data_service').setLevel(logging.DEBUG)

Contributing

When adding background service support to new sport managers:

  1. Import the background service
  2. Initialize in __init__ method
  3. Update data fetching method to use background service
  4. Add configuration options
  5. Test thoroughly
  6. Update documentation

License

This feature is part of the LEDMatrix project and follows the same license terms.