Browse Source

alive pusher

master
gsd 2 months ago
parent
commit
1a6e2972a2
  1. 25
      tradebot.facti13.external.py

25
tradebot.facti13.external.py

@ -6,6 +6,7 @@ from colors import *
from json import load
import asyncio
from steam.errors import Forbidden as STEAM_FORBIDDEN
import aiohttp
from backend_integration import BackendClient
@ -77,9 +78,13 @@ class SteamClient(SteamPy.Client):
backend : BackendClient = None
backend_checker_enable = False
backend_checker_is_runned = False
alive_checker_is_runned = False
async def on_ready(self):
info(f"Logged in as: {self.user}")
asyncio.ensure_future(self.backend_checker(60))
asyncio.ensure_future(self.alive_pusher())
async def on_connect(self):
await self.backend.pulse()
@ -93,7 +98,27 @@ class SteamClient(SteamPy.Client):
prices = await self.backend.prices(exit_if_error)
self.items = TradeChecker(prices)
async def alive_pusher(self):
if self.alive_checker_is_runned:
return
else:
self.alive_checker_is_runned = True
url = os.getenv("ALIVE_PUSH")
while url:
try:
async with aiohttp.ClientSession() as session:
async with session.get(os.getenv("ALIVE_PUSH") + f'${round(self.latency * 1000)}', ssl = False) as response:
tmp = await response.text()
except:
pass
async def backend_checker(self, timeout=60):
if self.backend_checker_is_runned:
return
else:
self.backend_checker_is_runned = True
if not self.backend_checker_enable:
info(f"Check backend stats every {timeout} seconds")
self.backend_checker_enable = True

Loading…
Cancel
Save