1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

feat: use exponential backoff algorithm when polling actions (#524)

##### SUMMARY

Replace the constant poll interval of 1 second, with a truncated
exponential back off algorithm with jitter.

Below is a suite of poll interval (in seconds) generated by the new
algorithm:
```
1.49
2.14
5.46
6.51
6.57
5.57
5.98
7.13
6.59
7.10
5.54
5.03
6.56
5.96
6.72
7.21
7.05
5.31
5.60
6.33
6.82
5.42
6.08
6.60
TOTAL: 140.77
```
This commit is contained in:
Jonas L 2024-07-04 15:07:05 +02:00 committed by GitHub
parent ecaeac1175
commit 19e586fa22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 11 deletions

View file

@ -0,0 +1,14 @@
from __future__ import annotations
from ansible_collections.hetzner.hcloud.plugins.module_utils.client import (
exponential_backoff_poll_interval,
)
def test_exponential_backoff_poll_interval():
poll_interval = exponential_backoff_poll_interval(base=1.0, multiplier=2, cap=5.0, jitter=0.0)
poll_max_retries = 25
results = [poll_interval(i) for i in range(poll_max_retries)]
assert sum(results) == 117.0
assert results[:6] == [1.0, 2.0, 4.0, 5.0, 5.0, 5.0]