Skip to content
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

Retry storage operations in case of ClientError. #1107

Merged
merged 5 commits into from
Oct 8, 2019

Conversation

serhiy-storchaka
Copy link
Contributor

Can fix the part of #1093.

@codecov
Copy link

codecov bot commented Oct 8, 2019

Codecov Report

Merging #1107 into master will increase coverage by 10.39%.
The diff coverage is 90%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1107       +/-   ##
===========================================
+ Coverage   78.74%   89.13%   +10.39%     
===========================================
  Files          38       38               
  Lines        4803     4833       +30     
  Branches      719      726        +7     
===========================================
+ Hits         3782     4308      +526     
+ Misses        920      398      -522     
- Partials      101      127       +26
Impacted Files Coverage Δ
neuromation/api/storage.py 96.63% <100%> (+1.41%) ⬆️
neuromation/api/utils.py 90% <80%> (-6.67%) ⬇️
neuromation/cli/version_utils.py 95.23% <0%> (+1.19%) ⬆️
neuromation/cli/config.py 66.34% <0%> (+2.88%) ⬆️
neuromation/api/url_utils.py 92.53% <0%> (+2.98%) ⬆️
neuromation/cli/parse_utils.py 100% <0%> (+4%) ⬆️
neuromation/cli/formatters/jobs.py 98% <0%> (+4%) ⬆️
neuromation/cli/root.py 98.59% <0%> (+7.04%) ⬆️
neuromation/api/images.py 97.63% <0%> (+7.08%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44da3a0...1caaf90. Read the comment docs.


def retries(msg: str) -> Iterator[ContextManager[None]]:
sleeptime = 0.0
for r in range(ATTEMPTS)[::-1]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is reversed iteration here?
I believe that the thing may be implemented simpler:

for r in range(ATTEMPTS):
    ...
    yield retry()
else:
    raise last_error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

if r:

@contextlib.contextmanager
def retry() -> Iterator[None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the function should be async?
IIUC an exception raised during the work (not the first coroutine call but in the middle of the coroutine unwinding) is not handled.

It would be nice to have a test for retries() to check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. There is asyncio.sleep() inside, so the context manager should be asynchronous.

@lgtm-com
Copy link

lgtm-com bot commented Oct 8, 2019

This pull request introduces 1 alert and fixes 2 when merging 10d2d72 into 44da3a0 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

fixed alerts:

  • 2 for Unused import

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

LGTM

@lgtm-com
Copy link

lgtm-com bot commented Oct 8, 2019

This pull request introduces 1 alert and fixes 2 when merging 1caaf90 into 44da3a0 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

fixed alerts:

  • 2 for Unused import

@serhiy-storchaka serhiy-storchaka merged commit 337307f into master Oct 8, 2019
@serhiy-storchaka serhiy-storchaka deleted the storage-cp-retry branch October 8, 2019 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants