Skip to content

Commit 10000c4

Browse files
committed
feat(afk.py): add detailed logging for AFK entries to aid in debugging
Add loguru logger to provide detailed debug information about AFK entries in a guild. This includes total entries and specifics of each entry, such as member ID, expiration status, and enforcement status. This change helps in diagnosing issues related to AFK entries. perf(afk.py): reduce AFK expiration check interval to 30 seconds Decrease the interval for the AFK expiration handler from 120 seconds to 30 seconds. This change ensures that expired AFK entries are processed more frequently, improving the responsiveness of the system to changes in AFK status.
1 parent 1da6bf3 commit 10000c4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/tux/database/controllers/afk.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from datetime import UTC, datetime
1111
from typing import TYPE_CHECKING, Any
1212

13+
from loguru import logger
14+
1315
from tux.database.controllers.base import BaseController
1416
from tux.database.models import AFK
1517

@@ -279,11 +281,26 @@ async def get_expired_afk_members(self, guild_id: int) -> list[AFK]:
279281
"""
280282
# Database stores naive UTC datetimes, use naive for comparison
281283
now = datetime.now(UTC).replace(tzinfo=None)
282-
return await self.find_all(
284+
285+
# First, get ALL AFK entries for this guild to debug
286+
all_entries = await self.find_all(filters=AFK.guild_id == guild_id)
287+
logger.debug(
288+
f"Total AFK entries in guild {guild_id}: {len(all_entries)}",
289+
)
290+
for entry in all_entries:
291+
logger.debug(
292+
f"AFK entry: member={entry.member_id}, until={entry.until}, "
293+
f"perm_afk={entry.perm_afk}, enforced={entry.enforced}, "
294+
f"expired={entry.until < now if entry.until else 'N/A'}",
295+
)
296+
297+
expired = await self.find_all(
283298
filters=(
284299
(AFK.guild_id == guild_id)
285300
& (AFK.perm_afk == False) # noqa: E712 - Temporary AFK only
286301
& (AFK.until.is_not(None)) # type: ignore[attr-defined]
287302
& (AFK.until < now) # type: ignore[arg-type]
288303
),
289304
)
305+
logger.debug(f"Expired AFK entries found: {len(expired)}")
306+
return expired

src/tux/modules/utility/afk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ async def check_afk(self, message: discord.Message) -> None:
415415
f"Error in check_afk listener for message {message.id}: {e}",
416416
)
417417

418-
@tasks.loop(seconds=120, name="afk_expiration_handler")
418+
@tasks.loop(seconds=30, name="afk_expiration_handler")
419419
async def handle_afk_expiration(self) -> None:
420420
"""Check AFK database at a regular interval, remove AFK from users with an entry that has expired."""
421421
# Skip AFK expiration processing during maintenance mode
@@ -474,7 +474,7 @@ async def handle_afk_expiration(self) -> None:
474474
async def before_handle_afk_expiration(self) -> None:
475475
"""Wait until the bot is ready."""
476476
await self.bot.wait_until_ready()
477-
logger.info("AFK expiration handler started (runs every 120 seconds)")
477+
logger.info("AFK expiration handler started (runs every 30 seconds)")
478478

479479
@handle_afk_expiration.error
480480
async def on_handle_afk_expiration_error(self, error: BaseException) -> None:

0 commit comments

Comments
 (0)