Implement BatchableAnalyzerInterface for centralized batch processing#26
Conversation
Add processEntity() and hasResults() methods to AISentimentsAnalyzer, enabling this analyzer to participate in the centralized batch system provided by the Analyze module. This replaces the need for module-specific batch handling and fixes the existing bug where $context['finished'] was never set — the centralized batch service handles context management now. Update documentation to reference the centralized batch UI and Drush command.
Use dev-develop branch for squizlabs/php_codesniffer v4 support.
|
Note: The |
Code Review: #26Reviewed the full diff (+58/-11 across 5 files), linked issue #25, the parent issue dxpr/analyze#15, and all sibling submodule PRs for cross-consistency. Medium: Bug fix is implicit — old buggy code still activeIssue #25 identifies a bug: Options:
Option 1 is the minimum for this PR. Leaving a known-buggy code path fully accessible without even a deprecation notice is a poor user experience. Medium: Output buffering inconsistencyThis PR calls Low: Unrelated formatting changes
Low: Existing batch infrastructure not deprecatedSame concern as brand_voice#13 — issue step 2 says to deprecate Positive notes
|
|
Review notes:
|
Architecture Review — Senior Drupal PerspectiveThe core implementation is minimal and correct (+26 lines of PHP logic). The Critical1.
|
Live Testing ResultsTested on dxpr-cms-2026-01-07 (Drupal 11.3.1, PHP 8.3, MySQL) with all 6 modules on FATAL:
|
render() throws LogicException in Drush CLI context because there is no render root. renderPlain() creates its own render context and works in both web and CLI.
Stop swallowing rate limit exceptions so the centralized batch service can catch them and retry with exponential backoff. Other exceptions are still caught and handled gracefully.
Implements BatchableAnalyzerInterface::countAnalyzedEntities() with a fast DB count query. No entity loading or rendering.
- Delete SentimentsBatchForm and SentimentsBatchService - Remove batch route, service definition, and task link - processEntity() now calls analyzeSentiments() directly instead of delegating through renderSummary(), returns FALSE on failure
|
One remaining concern after re-checking the latest commits: |
renderPlain() is deprecated in Drupal 10.3, removed in 12.0. renderInIsolation() creates its own render context and works in both web and CLI/Drush batch contexts.
|
Re-checking after the latest commits: my earlier |
|
One cleanup issue still needs attention before this is really “old path removed” rather than “old path half-removed”.
This is exactly the kind of leftover surface area that quietly degrades maintainability: the code looks centralized, but the UI still advertises a ghost path. Please remove the stale menu link instead of carrying dead wiring forward. |
Summary
BatchableAnalyzerInterfaceonAISentimentsAnalyzerwithprocessEntity()andhasResults()methods, enabling participation in the centralized batch system from the Analyze module.$context['finished']was never set in batch operations — the centralized batch service now handles context management.Dependencies
Closes #25
Test plan
analyze_ai_sentimentsmodule alongsideanalyze(with batch support from Add centralized batch processing infrastructure analyze#16)./admin/config/content/analyze-batchand verify "AI Sentiments Analysis" appears as a selectable analyzer.drush analyze:batch --analyzers=analyze_ai_sentiments_analyzer --types=node:article --limit=2and verify entities are processed.--forceand verify already-analyzed entities are skipped (processEntityreturnsFALSE).--forceand verify scores are deleted and regenerated.