mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +01:00
Add error handling to uptime checker
This commit is contained in:
parent
fd9074f89e
commit
07e10f0eb5
1 changed files with 11 additions and 2 deletions
|
@ -64,6 +64,7 @@ class UptimeCompetition(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.http = AsyncClient()
|
self.http = AsyncClient()
|
||||||
self._warning_posted = False
|
self._warning_posted = False
|
||||||
|
self.test_uptimes.add_exception_type(Exception)
|
||||||
self.test_uptimes.start()
|
self.test_uptimes.start()
|
||||||
self.last_result: list[UptimeEntry] = []
|
self.last_result: list[UptimeEntry] = []
|
||||||
self.task_lock = asyncio.Lock()
|
self.task_lock = asyncio.Lock()
|
||||||
|
@ -158,7 +159,11 @@ class UptimeCompetition(commands.Cog):
|
||||||
if max_retries := target.get("max_retries"):
|
if max_retries := target.get("max_retries"):
|
||||||
request_kwargs["max_retries"] = max_retries
|
request_kwargs["max_retries"] = max_retries
|
||||||
kwargs: Dict[str, str | int | None] = {"target_id": target["id"], "target": target["uri"], "notes": ""}
|
kwargs: Dict[str, str | int | None] = {"target_id": target["id"], "target": target["uri"], "notes": ""}
|
||||||
attempts, response = await self._test_url(target["uri"], **request_kwargs)
|
try:
|
||||||
|
attempts, response = await self._test_url(target["uri"], **request_kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
response = e
|
||||||
|
attempts = 1
|
||||||
if isinstance(response, Exception):
|
if isinstance(response, Exception):
|
||||||
kwargs["is_up"] = False
|
kwargs["is_up"] = False
|
||||||
kwargs["response_time"] = None
|
kwargs["response_time"] = None
|
||||||
|
@ -240,7 +245,11 @@ class UptimeCompetition(commands.Cog):
|
||||||
async def test_uptimes(self):
|
async def test_uptimes(self):
|
||||||
self.task_event.clear()
|
self.task_event.clear()
|
||||||
async with self.task_lock:
|
async with self.task_lock:
|
||||||
self.last_result = await self.do_test_uptimes()
|
try:
|
||||||
|
self.last_result = await self.do_test_uptimes()
|
||||||
|
except (Exception, ConnectionError):
|
||||||
|
print()
|
||||||
|
console.print_exception()
|
||||||
self.task_event.set()
|
self.task_event.set()
|
||||||
|
|
||||||
uptime = discord.SlashCommandGroup("uptime", "Commands for the uptime competition.")
|
uptime = discord.SlashCommandGroup("uptime", "Commands for the uptime competition.")
|
||||||
|
|
Loading…
Reference in a new issue