Browse Source

puukk

master
gsd 2 years ago
parent
commit
95c44ef2c8
  1. 14
      backend_integration.py
  2. 15
      paybot.facti13.py

14
backend_integration.py

@ -17,7 +17,7 @@ class BackendClient:
self.pulse_url = f"{os.getenv('BACKEND_URL')}/api/pulse"
self.vip_url = f"{os.getenv('BACKEND_URL')}/api/external/vip"
async def pulse(self):
async def pulse(self, exit_if_error = False):
async with aiohttp.ClientSession(cookies={
"secretkey":self.secret_key}) as session:
async with session.get(self.pulse_url, ssl=False) as response:
@ -30,6 +30,8 @@ class BackendClient:
except:
error("Backend not respond")
traceback.print_exc()
if exit_if_error:
sys.exit(200)
self.up = False
self.warn = False
return self.up
@ -55,7 +57,13 @@ class BackendClient:
return False
return False
async def prices(self):
async def prices(self, exit_if_error = False):
async with aiohttp.ClientSession() as session:
async with session.get(self.vip_url) as response:
return await response.json()
try:
return await response.json()
except:
traceback.print_exc()
if exit_if_error:
error("Cannot fetch prices")
sys.exit(200)

15
paybot.facti13.py

@ -18,6 +18,8 @@ class Client:
prices = {}
backend_checker_enabled = False
convert_map = {
"month":30*24*60*60,
"week":7*24*60*60,
@ -43,7 +45,16 @@ class Client:
print(await self.wallet.get_balance())
await self.backend.pulse()
await self.update_prices_from_server()
#Добавить фоновую проверку живности бека
asyncio.ensure_future(self.backend_checker(60))
async def backend_checker(self, timeout = 60):
if not self.backend_checker_enabled:
self.backend_checker_enabled = True
info(f"check backend every {timeout} seconds")
while True:
await self.backend.pulse(True)
await self.update_prices_from_server()
await asyncio.sleep(timeout)
def build_handler(self):
@self.qiwi_dp.transaction_handler()
@ -94,7 +105,7 @@ class Client:
if not self.prices:
error("cannot get prices from server")
sys.exit(228)
info(f"prices: {self.prices}")
#info(f"prices: {self.prices}")
def price_checker(self, amount):
seconds2give = 0

Loading…
Cancel
Save