forked from EverythingSuckz/TG-FileStreamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeepalive.py
More file actions
22 lines (20 loc) · 777 Bytes
/
Copy pathkeepalive.py
File metadata and controls
22 lines (20 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import asyncio
import logging
import aiohttp
from WebStreamer import Var
logger = logging.getLogger("keep_alive")
async def ping_server():
sleep_time = Var.PING_INTERVAL
logger.info("Started with {}s interval between pings".format(sleep_time))
while True:
await asyncio.sleep(sleep_time)
try:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(total=10)
) as session:
async with session.get(Var.URL) as resp:
logger.info("Pinged server with response: {}".format(resp.status))
except TimeoutError:
logger.warning("Couldn't connect to the site URL..")
except Exception:
logger.error("Unexpected error: ", exc_info=True)