I'm creating a Reddit bot using PRAW (Python Reddit API Wrapper) for a subreddit I moderate that comments on new submissions requesting that the poster comments on their post in order to comply with the posting rules. If the poster has not commented on their post within 1 hour then the bot should remove the post. The sequence of events looks like this:
The problem I have is with waiting for one hour. I cannot use sleep()
to block for one hour because the bot will need to process other posts that have been made in that time frame (i.e. posts are made every fifteen minutes but using sleep()
for one hour would cause the bot to fall behind). I also don't think I can use polling as checking for submissions is blocks the thread. To elaborate, I am checking for new submissions using for submission in subreddit.stream.submissions(skip_existing=True):
where subreddit.stream.submissions()
is a generator/ stream that yields whenever someone submits a post to the subreddit (Documentation here).
So at this point, I'm completely lost on where to go. I need to create a new task for every post that is made that runs through steps 1 to 4 without blocking more identical tasks being made whenever a post is submitted. If you could provide a pointer on which direction to go or how I might do this I would be grateful. In case you missed it, I'm using Python.
You might want to use 'RQ' (Redis Task Queue). It will add a new dependency in your application but you will get what you want. You can refer to the Docs here.