diff options
| author | 2019-05-06 18:52:24 -0600 | |
|---|---|---|
| committer | 2019-05-06 18:52:24 -0600 | |
| commit | 8ff59249b92cfbb69ae1ea5e8e1ac273b4ced4d6 (patch) | |
| tree | 06e179dcc185ff2befdfe4909791c1f41fabf2eb | |
| parent | Fixing the lint error -_- (diff) | |
| parent | Preventing multiple reddit background tasks from starting by checking if one ... (diff) | |
Merge pull request #360 from python-discord/reddit-task-bug-fix
Preventing the multiple reddit background tasks bug
| -rw-r--r-- | bot/cogs/reddit.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py index 2e3d32b2d..b5bd26e3d 100644 --- a/bot/cogs/reddit.py +++ b/bot/cogs/reddit.py @@ -31,6 +31,9 @@ class Reddit: self.prev_lengths = {} self.last_ids = {} + self.new_posts_task = None + self.top_weekly_posts_task = None + async def fetch_posts(self, route: str, *, amount: int = 25, params=None): """ A helper method to fetch a certain amount of Reddit posts at a given route. @@ -280,8 +283,10 @@ class Reddit: self.reddit_channel = self.bot.get_channel(Channels.reddit) if self.reddit_channel is not None: - self.bot.loop.create_task(self.poll_new_posts()) - self.bot.loop.create_task(self.poll_top_weekly_posts()) + if self.new_posts_task is None: + self.new_posts_task = self.bot.loop.create_task(self.poll_new_posts()) + if self.top_weekly_posts_task is None: + self.top_weekly_posts_task = self.bot.loop.create_task(self.poll_top_weekly_posts()) else: log.warning("Couldn't locate a channel for subreddit relaying.") |