10
10
from copy import deepcopy
11
11
12
12
from aiohttp import web
13
+ from tenacity import before_sleep_log , retry , stop_after_attempt , wait_fixed
13
14
14
15
from servicelib import openapi
15
16
from servicelib .application_keys import APP_CONFIG_KEY
22
23
log = logging .getLogger (__name__ )
23
24
24
25
26
+ RETRY_WAIT_SECS = 2
27
+ RETRY_COUNT = 20
28
+ CONNECT_TIMEOUT_SECS = 30
29
+
25
30
26
31
def get_server (servers , url ):
27
32
# Development server: http://{host}:{port}/{basePath}
@@ -30,7 +35,13 @@ def get_server(servers, url):
30
35
return server
31
36
raise ValueError ("Cannot find server %s in openapi specs" % url )
32
37
33
- #-----------------------
38
+
39
+ @retry ( wait = wait_fixed (RETRY_WAIT_SECS ),
40
+ stop = stop_after_attempt (RETRY_COUNT ),
41
+ before_sleep = before_sleep_log (log , logging .INFO ) )
42
+ async def get_specs (location ):
43
+ specs = await create_openapi_specs (location )
44
+ return specs
34
45
35
46
36
47
def setup (app : web .Application , * , debug = False ):
@@ -43,7 +54,7 @@ def setup(app: web.Application, *, debug=False):
43
54
#specs = await create_openapi_specs(location=cfg["location"])
44
55
loop = asyncio .get_event_loop ()
45
56
location = cfg ["location" ]
46
- specs = loop .run_until_complete ( create_openapi_specs (location ) )
57
+ specs = loop .run_until_complete ( get_specs (location ) )
47
58
48
59
# sets servers variables to current server's config
49
60
extra_api_urls = cfg .get ("extra_urls" , list ())
0 commit comments