SGA-A / c2c

Source code for the custom app exclusive to cc
MIT License
1 stars 0 forks source link

Hot reloading client modules #158

Closed SGA-A closed 1 week ago

SGA-A commented 2 weeks ago

We're moving our bot base to inherit from discord.Client instead of the extended commands.Bot. The tasks to be done are listed below:

SGA-A commented 2 weeks ago

We haven't created a branch for this yet and the changes are unstaged.

A single commit will be made to the main branch which closes this issue.

SGA-A commented 2 weeks ago

The migration has been successful and we are monitoring the bot for any more unusual issues after the migration. Some things to consider:

Hot reloading will most likely not be implemented any time soon due to the nature of how these commands are stored. It is planned but not right now.

More is to be considered when I come up with them. It's not fully ready for use after thorough testing and triaging has been made to prove it's robust

SGA-A commented 2 weeks ago

Are tasks running properly? If so, are they being cancelled gracefully when the bot shuts down?

Tasks are not running when the bot starts up leading me to believe that it also does not stop when the bot shuts down.

Take into consideration a task is just a function that is only starts when Task.start() is called and this only ever happens when an item is used or a temporary role is added.[1] With this in mind, it seems the only feasible solution is to create another parameters in the bot exports named tuple to contain an attribute named tasks. These tasks are then facilitated in the bot constructor by making it a private attribute of the bot instance. Cleanup will also need to be done within the polymorphised close method of the subclassed client by checking if there are any pending tasks and if that's the case, gracefully close them.

TL;DR: will need to add a new param to the BotExports named tuple to take in optional tasks. These are then added into the the bot instance as an attribute and all tasks start and end within the __init__ and close methods of the bot respectively.

[1]Tasks are only ever started when it's associated start method is called. However currently as the code is, it only ever starts during a command invocation involving a task.

SGA-A commented 1 week ago

I will not be working on hot reloading functionality just yet. Closed the issue for now mainly since the rest of the tasks mentioned were already resolved in the relevant commit.

Will be coming back to this, when I feel developing it.