sir-lancebot icon indicating copy to clipboard operation
sir-lancebot copied to clipboard

Add logic for preserving unloaded Cogs.

Open Shivansh-007 opened this issue 3 years ago ā€¢ 10 comments

This PR makes a Redis cache in bot.bot to store all the unloaded extensions, on every unload and load this cache would be edited in the desired manner, either removing it from it or adding it in the cache.

Now, coming to not loading the unloaded commands, on bot startup, just after Redis gets connected, the bot would run bot.get_unloaded_extensions and get all the unloaded extensions from the cache. These extensions would be skipped and not loaded, the skipping message would be logged. Once all these extensions are loaded, we compare and check which extensions are present in the cache and not the bot. This means these cogs are either removed or renamed.

A message containing all these "extra" cogs are sent to #dev-alerts and these cogs are removed from the cache.

Resolves: #705

Flow with screenshots

1: Cache containing 'bot.exts.evergreen.catify | bot.exts.evergreen.xkd'

Screenshot from 2021-05-18 15-37-50

2: After bot sends ^

Screenshot from 2021-05-18 15-43-34

3: On doing .exts unload ping

Screenshot from 2021-05-18 15-44-57

4: On doing .exts load ping

Screenshot from 2021-05-18 15-57-27

Todo

  • [x] There is a small bug in this, I will fix that soon, since the bot removes the cogs from the cache first and then performs the action, it will also remove the cogs which have been failed to auction.
  • [ ] Remove testing code
  • [ ] Add core-developers role to allowed mention, need to discuss if it should be allowed overall or just while the alert message is sent.

Shivansh-007 avatar May 18 '21 10:05 Shivansh-007

With your current approach, you store the cached unloads into a dict, then remove successfully unloaded cogs from the dict in load_extension, then compare the dict with the cached unloads to find missing cogs.

A better solution would be to just go ahead with loading the extension (and checking presence in the cache before loading), and storing a set of successfully unloaded cogs instead. Then, you can get all the unloads from the cache and clean up the ones that were not in the successful dict.

This can be done with a load_extensions method on the bot that keep tracks of extensions that were successfully unloaded locally. That way, there's no need to store a redundant instance attribute after startup. It would also reduce the chances of race conditions with getting the unloaded cogs/loading cogs/checking for not found cogs.

That would be possible if we make load_extensions an async function, since to check whether it exists within the async redis-cache or not it would be awaited. Hence I didn't do that.

Shivansh-007 avatar Jun 03 '21 14:06 Shivansh-007

Would that be an issue? It wouldn't be much unlike how you're getting the unloaded extensions after all. I'm not an async expert though

kosayoda avatar Jun 03 '21 14:06 kosayoda

Would that be an issue? It wouldn't be much unlike how you're getting the unloaded extensions after all. I'm not an async expert though

Not really but I would need to add await/async in the some places (The extensions cog, and bot/__main__.py probably).

Shivansh-007 avatar Jun 03 '21 14:06 Shivansh-007

File restructure has occurred, it may have been the cause of these conflicts.

Xithrius avatar Sep 05 '21 20:09 Xithrius

This PR is now up for grabs. Would anyone that's currently subscribed to this thread or just happened to see this comment like to take over this feature?

Xithrius avatar Feb 18 '22 01:02 Xithrius

Hello, Iā€™d like to have a go at this in a separate PR.

ToxicKidz avatar Feb 18 '22 01:02 ToxicKidz

@Xithrius Currently this PR is complete, only needs another core-dev approval. IIRC Chris was looking to review this, not sure how far he has got.

Shivansh-007 avatar Feb 18 '22 01:02 Shivansh-007

Cool okay šŸ‘ŒšŸ» , let me know if you need any help while going through the code @ToxicKidz.

Shivansh-007 avatar Feb 18 '22 01:02 Shivansh-007

Whoops, didn't mean to request another review from you, @Bluenix2. Sorry about that. You can ignore this notification.

Xithrius avatar Mar 23 '22 00:03 Xithrius

@ToxicKidz When you have the time, please resolve the file conflicts within this PR. Thanks!

Xithrius avatar Mar 23 '22 00:03 Xithrius

Due to the staleness of this PR, I'll be closing it. If anyone wants to pick it back up, feel free to do so.

Xithrius avatar Aug 18 '22 22:08 Xithrius