instances.create: expose retry settings, add exponential backoff#48
Merged
instances.create: expose retry settings, add exponential backoff#48
Conversation
shamrin
commented
Oct 23, 2025
| pricing: Optional[Pricing] = None, | ||
| coupon: Optional[str] = None) -> Instance: | ||
| coupon: Optional[str] = None, | ||
| *, |
Contributor
Author
There was a problem hiding this comment.
* is a keyword-only argument marker, probably a good idea to do it for all new arguments.
bemyak
reviewed
Oct 23, 2025
Comment on lines
+171
to
+194
| # Wait for instance to enter provisioning state with timeout | ||
| MAX_WAIT_TIME = 60 # Maximum wait time in seconds | ||
| POLL_INTERVAL = 0.5 # Time between status checks | ||
|
|
||
| start_time = time.time() | ||
| interval = min(initial_interval, max_interval) | ||
| deadline = time.monotonic() + max_wait_time | ||
| while True: | ||
| instance = self.get_by_id(id) | ||
| if instance.status != InstanceStatus.ORDERED: | ||
| return instance | ||
|
|
||
| if time.time() - start_time > MAX_WAIT_TIME: | ||
| now = time.monotonic() | ||
| if now >= deadline: | ||
| raise TimeoutError( | ||
| f"Instance {id} did not enter provisioning state within {MAX_WAIT_TIME} seconds") | ||
| f"Instance {id} did not enter provisioning state within {max_wait_time:.1f} seconds") | ||
|
|
||
| time.sleep(POLL_INTERVAL) | ||
| time.sleep(min(interval, deadline - now)) | ||
| interval = min(interval * backoff_coefficient, max_interval) |
There was a problem hiding this comment.
It's not a big change, but it creates less variables and I guess it's a bit easier to read:
import itertools # ← at the top
# Wait for instance to enter provisioning state with timeout
start_time = time.monotonic()
for i in itertools.count():
instance = self.get_by_id(id)
if instance.status != InstanceStatus.ORDERED:
return instance
time_left = max_wait_time - (time.monotonic() - start_time)
if time_left < 0:
raise TimeoutError(
f"Instance {id} did not enter provisioning state within {max_wait_time:.1f} seconds")
interval = initial_interval * backoff_coefficient ** i
time.sleep(min(interval, max_interval, time_left))
Contributor
Author
There was a problem hiding this comment.
Thanks! I've used some ideas from your version.
bemyak
reviewed
Oct 23, 2025
98d562d to
68ef37a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #48 +/- ##
==========================================
- Coverage 87.98% 87.36% -0.62%
==========================================
Files 21 21
Lines 1124 1148 +24
==========================================
+ Hits 989 1003 +14
- Misses 135 145 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.