fix(es): use long-polling to watch reindex tasks#34
Conversation
rerowep
commented
Jul 1, 2026
- Replace fixed-interval sleep polling with ES long-polling (wait_for_completion + timeout) to cut down on request overhead
- Add _log_task_progress helper for consistent progress reporting
- Treat NotFoundError and closed-index RequestError as task completion, and timeout TransportError as an expected retry signal
- Include the index name in update-mapping error messages
- Rename --inplace short option from -i to -p to avoid clashing with --interval on the same command
WalkthroughThe Elasticsearch reindex task watcher was rewritten to use server-side long-polling via Estimated code review effort: 3 (Moderate) | ~20 minutes Changes
Related issues: None found. Related PRs: None found. Suggested labels: enhancement, cli Suggested reviewers: None available from provided context. 🐰 A rabbit watched a task take flight, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
rero_invenio_base/cli/es/index.py (1)
31-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd missing Sphinx return metadata.
The new docstrings omit
:rtype:;_log_task_progressalso omits:returns:. As per coding guidelines, use Sphinx-style docstrings with:param x:,:returns:,:rtype:format.<coding_guidelines>Proposed fix
def _log_task_progress(task, count): """Fetch current task status and print a one-line progress update. :param task: task id. :param count: elapsed seconds to display. + :returns: None. + :rtype: None """ @@ :param interval: seconds to wait per poll (passed as timeout to the tasks API). :param verbose: print task progress on each poll. :returns: True on success, False if the task reported failures. + :rtype: bool """🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rero_invenio_base/cli/es/index.py` around lines 31 - 54, The docstrings for _log_task_progress and _watch_reindex_task are missing required Sphinx return metadata. Update these docstrings to include :returns: and :rtype: entries, keeping the existing :param annotations, so the function contracts match the coding guidelines and are consistent with other CLI helpers in index.py.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rero_invenio_base/cli/es/index.py`:
- Around line 37-44: The progress update in the task-watching block is too broad
because the exception handler in the CLI task polling logic swallows all errors
and can hide unrelated bugs. Update the try/except around
current_search_client.tasks.get in the watch command to catch TransportError
instead of Exception, since NotFoundError and RequestError already fall under
that hierarchy, and keep the fallback click.secho path only for those
Elasticsearch transport failures.
- Around line 269-270: The current broad except in the Elasticsearch index
command catches all exceptions, but this block should only handle
client/index-operation failures. Narrow the handler around the Elasticsearch
operation in the CLI flow so it catches the specific Elasticsearch client
exception type(s) used by the index action, while leaving unrelated bugs to fail
normally; keep the existing click.secho error reporting for those targeted
failures.
---
Nitpick comments:
In `@rero_invenio_base/cli/es/index.py`:
- Around line 31-54: The docstrings for _log_task_progress and
_watch_reindex_task are missing required Sphinx return metadata. Update these
docstrings to include :returns: and :rtype: entries, keeping the existing :param
annotations, so the function contracts match the coding guidelines and are
consistent with other CLI helpers in index.py.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: be2201e6-8308-420d-a684-91a2743e2fa7
📒 Files selected for processing (1)
rero_invenio_base/cli/es/index.py
* Replace fixed-interval sleep polling with ES long-polling (wait_for_completion + timeout) to cut down on request overhead * Add _log_task_progress helper for consistent progress reporting * Treat NotFoundError and closed-index RequestError as task completion, and timeout TransportError as an expected retry signal * Include the index name in update-mapping error messages * Rename --inplace short option from -i to -p to avoid clashing with --interval on the same command Co-Authored-by: Peter Weber <peter.weber@rero.ch>
3d26128 to
1b95acb
Compare