Open Source: Python Discord Bot
A contribution to the Python Discord community's bot. I added retries with exponential backoff to four cogs, a single startup alert for moderators, and unit tests for the failure cases.
4
COGS HARDENED
Silent startup failure
FAILURE MODE FIXED
Overview
The Python Discord bot runs in production for one of the biggest programming communities on Discord. My contribution fixed a problem where cogs (bot extensions) could fail during startup if an HTTP service they depend on was down. Nothing got reported when that happened, so moderators had no idea that some features weren't working.
What I did
- Added retries with exponential backoff to the four affected cogs
(
filtering,reminders,python_news,superstarify). Initialization is retried up to a configurableMAX_RETRIES, and after that the error gets raised instead of swallowed. - Added a moderator alert. Once startup finishes, the bot sends one message to the mod-log channel listing every cog that failed along with its error, and pings the moderator team.
- Wrote unit tests for the success and failure paths of each cog. The tests mock the HTTP calls and count the sleep calls to check that the backoff really works the way it should.
What I learned
Working on a production open-source project is very different from coding on my own. The maintainers cared a lot about how failures are handled and reported, and about tests. Getting the alert down to one message instead of four mattered about as much to them as the retry logic did.
APPENDIX A // MEDIA
IMAGE SLOT · AWAITING UPLOAD