Skip to content

Convert status_task to nextcord ext.tasks.loop - #50

Merged
brah merged 1 commit into
mainfrom
modernize-status-task
Jun 16, 2026
Merged

Convert status_task to nextcord ext.tasks.loop#50
brah merged 1 commit into
mainfrom
modernize-status-task

Conversation

@brah

@brah brah commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Replaces the hand-rolled presence loop (while not self.bot.is_closed() started via bot.loop.create_task(self.initialize()) in __init__) with the modern @tasks.loop(seconds=15) helper.

  • Toggle state moves from a loop-local to self._display_streams.
  • One-time startup (wait_until_ready → Tautulli init → version logging) moves to a @before_loop hook.
  • cog_unload cancels the loop; the per-iteration try/except is kept so a Tautulli hiccup logs and the loop keeps ticking.
  • On shutdown the loop is cancelled cleanly: commands.Bot.close() unloads cogs (firing cog_unload) before the gateway and the shared Tautulli session close. Updated the PlexBot.close() docstring to describe that.

Verification: ruff clean, 30/30 tests pass, runtime smoke test (loop start → before_loop init → tick sets presence → toggle flips → cog_unload cancels).

🤖 Generated with Claude Code

Replace the hand-rolled presence loop (a while-not-is_closed() loop
started via bot.loop.create_task in __init__) with the modern
@tasks.loop(seconds=15) helper.

The toggle state moves from a loop-local to self._display_streams, the
one-time startup work (wait_until_ready, Tautulli init, version logging)
moves to a @before_loop hook, and cog_unload cancels the loop instead of
a tracked task handle. The per-iteration try/except is kept so a Tautulli
hiccup logs and the loop keeps ticking, matching the old resilience.

This removes the fragile bot.loop.create_task(self.initialize()) in
__init__ and the manual asyncio.sleep pacing. On shutdown the loop is
cancelled cleanly: commands.Bot.close() unloads cogs (firing cog_unload)
before the gateway and the shared Tautulli session close. Updated the
PlexBot.close() docstring to describe that mechanism.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@brah
brah merged commit 69b92b6 into main Jun 16, 2026
2 checks passed
@brah
brah deleted the modernize-status-task branch June 16, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant