Skip to content

refactor(baseball): use background_data_service via data_manager#19

Merged
ChuckBuilds merged 1 commit intomainfrom
refactor/baseball-bg-service
Feb 12, 2026
Merged

refactor(baseball): use background_data_service via data_manager#19
ChuckBuilds merged 1 commit intomainfrom
refactor/baseball-bg-service

Conversation

@ChuckBuilds
Copy link
Copy Markdown
Owner

@ChuckBuilds ChuckBuilds commented Feb 12, 2026

Summary

  • Wire manager.py to delegate data fetching to the existing data_manager.py, which already has full background_data_service integration (submit_fetch_request with callbacks, request tracking, and sync fallback)
  • This brings the baseball-scoreboard in line with basketball, football, hockey, and soccer scoreboard plugins which all use background_data_service for async background fetching
  • Old synchronous fetch logic preserved as _fetch_league_data_sync() fallback if data_manager import fails

Changes

  • manager.py: Import BaseballDataManager, initialize in __init__(), delegate _fetch_league_data() to data manager, add MiLB format converter, update cleanup()
  • manifest.json: Bump to v1.0.5, add monorepo fields (repo, branch, plugin_path)
  • plugins.json: Sync last_updated to 2026-02-12 to match manifest

Test plan

  • Verify data_manager.py imports resolve when running as a plugin
  • Check logs for "Baseball data manager initialized with background service support"
  • Verify ESPN data fetching works via background service (MLB, NCAA Baseball)
  • Verify MiLB data fetching works via data_manager
  • Test fallback: if data_manager import fails, sync fetch still works

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added background data fetching for the baseball-scoreboard plugin for improved performance and reliability.
  • Chores

    • Updated baseball-scoreboard plugin to version 1.0.5.
    • Updated plugin registry metadata and configuration entries.

Wire manager.py to delegate data fetching to the existing data_manager.py,
which already has full background_data_service integration (submit_fetch_request
with callbacks, request tracking, and sync fallback). This brings baseball in
line with the basketball, football, hockey, and soccer scoreboard plugins.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Version 1.0.5 release of the baseball-scoreboard plugin introduces optional background data fetching via a new data_manager module. Metadata updated across plugins.json and manifest.json, while manager.py adds data_manager initialization with fallback to synchronous ESPN API calls when unavailable.

Changes

Cohort / File(s) Summary
Metadata & Registry
plugins.json, plugins/baseball-scoreboard/manifest.json
Version bumped to 1.0.5 with updated timestamps. Manifest adds repo, branch, and plugin_path fields; introduces new 1.0.5 version entry with ledmatrix_min constraint.
Core Plugin Logic
plugins/baseball-scoreboard/manager.py
Adds optional BaseballDataManager integration with graceful fallback to sync behavior. New methods: _fetch_via_data_manager() for async data retrieval and _convert_milb_game() for data format alignment. Enhanced error handling and logging throughout fetch paths.

Sequence Diagram

sequenceDiagram
    participant Plugin as BaseballScoreboardPlugin
    participant DataMgr as BaseballDataManager
    participant ESPN as ESPN API
    
    Plugin->>DataMgr: Initialize (attempt)
    alt data_manager available
        DataMgr-->>Plugin: Instance created
        Note over Plugin: Ready for async fetching
    else Initialization fails
        Plugin-->>Plugin: Set data_manager to None
        Note over Plugin: Will use sync fallback
    end
    
    Plugin->>Plugin: fetch_league_data()
    alt data_manager exists
        Plugin->>DataMgr: _fetch_via_data_manager()
        DataMgr-->>Plugin: Return game data
        Plugin->>Plugin: _convert_milb_game() (if needed)
    else no data_manager
        Plugin->>ESPN: Direct API call (sync)
        ESPN-->>Plugin: Return game data
    end
    
    Plugin-->>Plugin: Cleanup & reset data_manager
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A scoreboard hops with data so bright,
Background fetching now runs day and night,
When data_manager's present, async takes flight,
But sync's always there as a fallback site,
Version 1.0.5 shines ever so right! ⚾✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring: delegating baseball data fetching to a background data service via a new data_manager module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/baseball-bg-service

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
plugins/baseball-scoreboard/manager.py (3)

195-202: Initialization order: data_manager is set up after self.initialized = True.

This is fine since data_manager is optional and the plugin functions without it, but worth noting: if any code between self.initialized = True (line 193) and line 196 were to trigger update() on another thread, self.data_manager wouldn't exist yet. Currently this isn't a problem since update() is called externally after __init__ completes, but moving the data_manager init to just before self.initialized = True would be slightly more defensive.


393-395: Remove unused variable e (flagged by Ruff F841).

logger.exception() already captures the full traceback automatically, so the as e binding is unnecessary.

🔧 Proposed fix
-        except Exception as e:
+        except Exception:
             self.logger.exception(f"Error fetching {league_key} via data manager, falling back to sync")
             return self._fetch_league_data_sync(league_key, league_config)

397-423: _convert_milb_game sets name to empty string — verify downstream compatibility.

The ESPN path (_extract_game_info, line 509) populates name with displayName, but this converter leaves it as ''. The display code appears to use abbrev for rendering, so this is likely fine, but it's a subtle inconsistency.

Also minor: venue is '' here vs. 'Unknown Venue' in the ESPN path (line 528). Consider aligning the defaults for consistency.

🔧 Optional: align defaults with ESPN path
             'home_team': {
-                'name': '',
+                'name': milb_data.get('home_team', 'Unknown'),
                 'abbrev': milb_data.get('home_team', ''),
                 ...
             },
             'away_team': {
-                'name': '',
+                'name': milb_data.get('away_team', 'Unknown'),
                 'abbrev': milb_data.get('away_team', ''),
                 ...
             },
             ...
-            'venue': ''
+            'venue': milb_data.get('venue', 'Unknown Venue')
         }

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChuckBuilds ChuckBuilds merged commit 590b916 into main Feb 12, 2026
1 check passed
@ChuckBuilds ChuckBuilds deleted the refactor/baseball-bg-service branch February 12, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant