fix(commands:iplocalise|Network): close TUXBOT-BOT-4T, close TUXBOT-BOT-4S

This commit is contained in:
Romain J 2021-05-16 17:07:26 +02:00
parent f8f56add97
commit 09e69166ad
3 changed files with 23 additions and 7 deletions

View file

@ -120,13 +120,24 @@ async def get_ipwhois_result(loop, ip: str) -> NoReturn | dict:
cache=Cache.MEMORY, cache=Cache.MEMORY,
namespace="network", namespace="network",
) )
async def get_ipinfo_result(apikey: str, ip: str) -> dict: async def get_ipinfo_result(loop, apikey: str, ip: str) -> dict:
def _get_ipinfo_result(_ip: str) -> NoReturn | dict:
"""
Q. Why no getHandlerAsync ?
A. Use of this return "Unclosed client session" and "Unclosed connector"
"""
try:
handler = ipinfo.getHandler(apikey, request_options={"timeout": 7})
return (handler.getDetails(ip)).all
except RequestQuotaExceededError:
return {}
try: try:
handler = ipinfo.getHandlerAsync( return await asyncio.wait_for(
apikey, request_options={"timeout": 7} loop.run_in_executor(None, _get_ipinfo_result, str(ip)),
timeout=8,
) )
return (await handler.getDetails(ip)).all except asyncio.exceptions.TimeoutError:
except RequestQuotaExceededError:
return {} return {}

View file

@ -103,6 +103,8 @@ class Network(commands.Cog):
self._peeringdb_net = await s.json() self._peeringdb_net = await s.json()
except asyncio.exceptions.TimeoutError: except asyncio.exceptions.TimeoutError:
pass pass
else:
log.log(logging.INFO, "_update_peering_db")
# ========================================================================= # =========================================================================
# ========================================================================= # =========================================================================
@ -126,7 +128,7 @@ class Network(commands.Cog):
ip_hostname = await get_hostname(self.bot.loop, str(ip_address)) ip_hostname = await get_hostname(self.bot.loop, str(ip_address))
ipinfo_result = await get_ipinfo_result( ipinfo_result = await get_ipinfo_result(
self.__config.ipinfoKey, ip_address self.bot.loop, self.__config.ipinfoKey, ip_address
) )
ipwhois_result = await get_ipwhois_result(self.bot.loop, ip_address) ipwhois_result = await get_ipwhois_result(self.bot.loop, ip_address)

View file

@ -332,7 +332,10 @@ class Tux(commands.AutoShardedBot):
self.console.log( self.console.log(
"Canceling", task.get_name(), f"({task.get_coro()})" "Canceling", task.get_name(), f"({task.get_coro()})"
) )
task.cancel() try:
task.cancel()
except Exception as e:
self.console.log(e)
await asyncio.gather(*pending, return_exceptions=False) await asyncio.gather(*pending, return_exceptions=False)
await super().close() await super().close()