Merge pull request #1272 from yuvipanda/exponential-function

Move exponential backoff into a function
This commit is contained in:
Yuvi Panda
2017-07-26 15:38:01 -07:00
committed by GitHub
3 changed files with 116 additions and 44 deletions

View File

@@ -20,7 +20,7 @@ from .. import __version__
from .. import orm
from ..objects import Server
from ..spawner import LocalProcessSpawner
from ..utils import url_path_join, DT_SCALE
from ..utils import url_path_join, exponential_backoff
# pattern for the authentication token header
auth_header_pat = re.compile(r'^(?:token|bearer)\s+([^\s]+)$', flags=re.IGNORECASE)
@@ -641,7 +641,8 @@ class UserSpawnHandler(BaseHandler):
# record redirect count in query parameter
if redirects:
self.log.warning("Redirect loop detected on %s", self.request.uri)
yield gen.sleep(min(1 * (DT_SCALE ** redirects), 10))
# add capped exponential backoff where cap is 10s
yield gen.sleep(min(1 * (2 ** redirects), 10))
# rewrite target url with new `redirects` query value
url_parts = urlparse(target)
query_parts = parse_qs(url_parts.query)