Files
FileStreamBot/WebStreamer/utils/keepalive.py

19 lines
625 B
Python
Raw Normal View History

2022-01-02 19:22:16 +05:30
import asyncio
2021-06-05 11:56:44 +05:30
import logging
2022-01-02 19:22:16 +05:30
import aiohttp
import traceback
from WebStreamer.vars import Var
async def ping_server():
sleep_time = Var.PING_INTERVAL
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:
logging.info("Pinged server with response: {}".format(resp.status))
except TimeoutError:
logging.warning("Couldn't connect to the site URL..!")
except Exception:
traceback.print_exc()