-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathserver.py
90 lines (36 loc) · 1.38 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import logging
from aiohttp import web
import asyncio
import aiohttp
import traceback
####################################################################################################
WEB_URL = "https://vegeta-private.onrender.com/"
WEB_SLEEP = 4*60
####################################################################################################
logger = logging.getLogger(__name__)
routes = web.RouteTableDef()
@routes.get('/', allow_head=True)
async def hello(request):
return web.Response(text="Hello, world!")
def web_server():
web_app = web.Application(client_max_size=300000)
web_app.add_routes(routes)
return web_app
async def keep_alive():
if WEB_URL:
while True:
await asyncio.sleep(WEB_SLEEP)
try:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10)
) as session:
async with session.get(WEB_URL) as resp:
logger.info(
"Pinged {} with response: {}".format(
WEB_URL, resp.status
)
)
except asyncio.TimeoutError:
logger.warning("Couldn't connect to the site URL..!")
except Exception:
traceback.print_exc()