diff options
| author | 2024-03-26 17:52:13 +0000 | |
|---|---|---|
| committer | 2024-03-26 17:52:13 +0000 | |
| commit | 5f2f10c698467bfc6a8012d4ed3f02257a4188ef (patch) | |
| tree | adef5b99396048e807935b83673fba5f59deaa54 | |
| parent | Capture cog load times using sentry performance tracking (diff) | |
Add sentry performance spans to news cog
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/info/python_news.py | 30 | 
1 files changed, 17 insertions, 13 deletions
| diff --git a/bot/exts/info/python_news.py b/bot/exts/info/python_news.py index e06c82bb8..c786a9d19 100644 --- a/bot/exts/info/python_news.py +++ b/bot/exts/info/python_news.py @@ -4,6 +4,7 @@ from datetime import UTC, datetime, timedelta  import discord  import feedparser +import sentry_sdk  from bs4 import BeautifulSoup  from discord.ext.commands import Cog  from discord.ext.tasks import loop @@ -43,6 +44,22 @@ class PythonNews(Cog):          self.webhook: discord.Webhook | None = None          self.seen_items: dict[str, set[str]] = {} +    async def cog_load(self) -> None: +        """Load all existing seen items from db and create any missing mailing lists.""" +        with sentry_sdk.start_span(description="Fetch mailing lists from site"): +            response = await self.bot.api_client.get("bot/mailing-lists") + +        for mailing_list in response: +            self.seen_items[mailing_list["name"]] = set(mailing_list["seen_items"]) + +        with sentry_sdk.start_span(description="Update site with new mailing lists"): +            for mailing_list in ("pep", *constants.PythonNews.mail_lists): +                if mailing_list not in self.seen_items: +                    await self.bot.api_client.post("bot/mailing-lists", json={"name": mailing_list}) +                    self.seen_items[mailing_list] = set() + +        self.fetch_new_media.start() +      async def cog_unload(self) -> None:          """Stop news posting tasks on cog unload."""          self.fetch_new_media.cancel() @@ -225,19 +242,6 @@ class PythonNews(Cog):              email_information = await resp.json()          return thread_information, email_information -    async def cog_load(self) -> None: -        """Load all existing seen items from db and create any missing mailing lists.""" -        response = await self.bot.api_client.get("bot/mailing-lists") -        for mailing_list in response: -            self.seen_items[mailing_list["name"]] = set(mailing_list["seen_items"]) - -        for mailing_list in ("pep", *constants.PythonNews.mail_lists): -            if mailing_list not in self.seen_items: -                await self.bot.api_client.post("bot/mailing-lists", json={"name": mailing_list}) -                self.seen_items[mailing_list] = set() - -        self.fetch_new_media.start() -  async def setup(bot: Bot) -> None:      """Add `News` cog.""" | 
