johnmaguire / Cardinal

A Python IRC bot, designed to make adding functionality quick and simple. (est. 2013)
MIT License
100 stars 38 forks source link

Unload plugins when disconnected from server #195

Closed johnmaguire closed 3 years ago

johnmaguire commented 3 years ago

I noticed in Cardinal logs that the ticker plugin was having tick() called multiple times at each 15 minute interval. Some of the logs showed the latest configuration, and some showed an older configuration. I also saw that my API usage on IEX had been slowly increasing over the past month. However, a single message was sent to the ticker channel.

I believe that when Cardinal is disconnected from the server, CardinalBotFactory spawns a new instance of CardinalBot, with its own set of plugins. The original CardinalBot instance never has its plugins unloaded, so close() in ticker is never called, and it just keeps chugging along.

We need to make sure we close all plugins when disconnected from a server. The alternative would be to share the PluginManager across multiple CardinalBot instances, but this comes with other issues - namely that any plugin which has stored cardinal (CardinalBot) somewhere on self would have a stale copy of the bot.

johnmaguire commented 3 years ago

I've been watching IEX API graphs and commit 284e5f9 seems to have resolved this.