diff options
| author | 2020-05-01 15:54:18 +0100 | |
|---|---|---|
| committer | 2020-05-01 15:54:18 +0100 | |
| commit | 8647fd856fc23cf5f4162498f44bbcd9c576de44 (patch) | |
| tree | c0329d24fc573086d39bd117bd3075d1a2d7ce54 | |
| parent | Added ignoring maillist when no recent threads (this month) in `News` cog (diff) | |
Merge the two asynchronous tasks into one to prevent race conditions
| -rw-r--r-- | bot/cogs/news.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/bot/cogs/news.py b/bot/cogs/news.py index ff2277283..a81a50f21 100644 --- a/bot/cogs/news.py +++ b/bot/cogs/news.py @@ -37,8 +37,13 @@ class News(Cog): async def start_tasks(self) -> None: """Start the tasks for fetching new PEPs and mailing list messages.""" - self.post_pep_news.start() - self.post_maillist_news.start() + self.fetch_new_media.start() + + @loop(minutes=20) + async def fetch_new_media(self) -> None: + """Fetch new mailing list messages and then new PEPs.""" + await self.post_maillist_news() + await self.post_pep_news() async def sync_maillists(self) -> None: """Sync currently in-use maillists with API.""" @@ -67,7 +72,6 @@ class News(Cog): if mail["name"].split("@")[0] in constants.PythonNews.mail_lists: self.webhook_names[mail["name"].split("@")[0]] = mail["display_name"] - @loop(minutes=20) async def post_pep_news(self) -> None: """Fetch new PEPs and when they don't have announcement in #python-news, create it.""" # Wait until everything is ready and http_session available @@ -113,7 +117,6 @@ class News(Cog): # Apply new sent news to DB to avoid duplicate sending await self.bot.api_client.put("bot/bot-settings/news", json=payload) - @loop(minutes=20) async def post_maillist_news(self) -> None: """Send new maillist threads to #python-news that is listed in configuration.""" await self.bot.wait_until_guild_available() @@ -223,8 +226,7 @@ class News(Cog): def cog_unload(self) -> None: """Stop news posting tasks on cog unload.""" - self.post_pep_news.cancel() - self.post_maillist_news.cancel() + self.fetch_new_media.cancel() def setup(bot: Bot) -> None: |