Skip to content

Add a progress callback to the wait operation function #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

saimanikant
Copy link
Collaborator

Pull Request Template

Description

Addressing #86
Added tests.

Checklist

Please complete the following checklist before submitting your pull request:

  • I have tested these changes locally and verified that they work as intended.
  • I have updated any documentation as needed to reflect these changes (if appropriate)
  • I have verified that these changes to the best of my knowledge do not introduce any security vulnerabilities.
  • Unit tests have been added (if appropriate)
  • Test-cases have been added (if appropriate)
  • Testing instructions have been added (if appropriate)

@saimanikant saimanikant linked an issue Apr 2, 2025 that may be closed by this pull request
@github-actions github-actions bot added the enhancement New features or code improvements label Apr 2, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.33%. Comparing base (6323797) to head (2219bd0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
- Coverage   84.99%   84.33%   -0.67%     
==========================================
  Files          19       19              
  Lines        1193     1200       +7     
==========================================
- Hits         1014     1012       -2     
- Misses        179      188       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -281,6 +282,7 @@ def wait_for(
interval: float = 0.1,
cap: float = 2.0,
raise_on_error: bool = False,
progress_handler: Callable[[int], None] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The operation progress is a float (between 0 and 1). Why the callback signature says it's an int?
  • The function can wait for a list of operations. How can a client know to which operation the progress applies to? Maybe we could add the operation id (string) an additional argument to the callback.

Comment on lines 312 to 314
if progress_handler is not None:
for op in ops:
progress_handler(op.progress)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a loop over the operations few lines above. Just embed this condition in there.

Comment on lines 127 to 128
def handler(current_progress):
log.info(f"{current_progress * 100.0}% completed")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you defined a callback that stores the progress data, you can then assert on it. For instance to verify that the callback was called at least say twice, that at the end progress is 1, etc.

Also, please add a test that verifies the case of multiple operations.

@@ -296,17 +314,19 @@ def wait_for(
ops = self._operations(operation_ids)
so_far = hf.format_timespan(time.time() - start)
log.debug(f"Waiting for {len(operation_ids)} operations to complete, {so_far} so far")
if self.client.binary_config.debug:
if progress_handler is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditions on self.client.binary_config.debug and progress_handler are not related. We should be able to print debug logs even if there's no progress_handler. I'd just do the loop twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features or code improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a progress callback to the wait operation functions
3 participants