-
-
Notifications
You must be signed in to change notification settings - Fork 42
removed tasks.loop & added call_later for better task scheduling #920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR replaces the polling-based reminder loop with precise scheduling via bot.loop.call_later, ensuring reminders fire on time, cleans up sent reminders, and streamlines initialization and UI messages. Sequence diagram for scheduling and sending reminders with call_latersequenceDiagram
participant User as actor User
participant Bot as Bot
participant DB as DatabaseController
User->>Bot: /remindme command
Bot->>DB: insert_reminder(...)
DB-->>Bot: reminder_obj
Bot->>Bot: bot.loop.call_later(seconds, send_reminder(reminder_obj))
Note over Bot: After 'seconds' delay
Bot->>DB: delete_reminder_by_id(reminder_obj.reminder_id)
Bot->>User: Send reminder message
Class diagram for updated RemindMe cog and reminder schedulingclassDiagram
class RemindMe {
- bot: Tux
- db: DatabaseController
- _initialized: bool
+ send_reminder(reminder: Reminder)
+ on_ready()
+ remindme(ctx, seconds, reminder)
}
class DatabaseController {
+ get_all_reminders()
+ insert_reminder(...)
+ delete_reminder_by_id(reminder_id)
}
class Reminder {
+ reminder_id: int
+ reminder_user_id: int
+ reminder_content: str
+ reminder_expires_at: datetime
}
RemindMe --> DatabaseController
RemindMe --> Reminder
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Deploying tux with
|
| Latest commit: |
e063768
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0eb966da.tux-afh.pages.dev |
| Branch Preview URL: | https://remindme-revamp.tux-afh.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @RainzDev - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Potential issue with passing coroutine to asyncio.create_task in call_later. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tux/cogs/utility/remindme.py:144` </location>
<code_context>
logger.error(f"Error creating reminder: {e}")
+ self.bot.loop.call_later(seconds, asyncio.create_task, self.send_reminder(ctx.author, reminder_obj))
+
await ctx.reply(embed=embed, ephemeral=True)
</code_context>
<issue_to_address>
Potential issue with passing coroutine to asyncio.create_task in call_later.
create_task requires a coroutine object, not a function and arguments. Use a lambda to wrap the call: self.bot.loop.call_later(seconds, lambda: asyncio.create_task(self.send_reminder(ctx.author, reminder_obj))).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
tux/cogs/utility/remindme.py
Outdated
|
|
||
| logger.error(f"Error creating reminder: {e}") | ||
|
|
||
| self.bot.loop.call_later(seconds, asyncio.create_task, self.send_reminder(ctx.author, reminder_obj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential issue with passing coroutine to asyncio.create_task in call_later.
create_task requires a coroutine object, not a function and arguments. Use a lambda to wrap the call: self.bot.loop.call_later(seconds, lambda: asyncio.create_task(self.send_reminder(ctx.author, reminder_obj))).
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #920 +/- ##
========================================
- Coverage 8.92% 8.92% -0.01%
========================================
Files 121 121
Lines 10269 10328 +59
Branches 1255 1322 +67
========================================
+ Hits 917 922 +5
- Misses 9278 9327 +49
- Partials 74 79 +5
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
|
Not done yet tho, obviously, since |
|
potential architecture issue: |
|
as this pull is still in progress and not ready for review/merge yert, I'm going to go ahead and convert it to a draft. |
Yes, that's why I mentioned about the on_ready part before. If a bot restarts, on_ready will loop through the database for reminders that haven't met the deadline yet. If there are reminders that aren't done, it'll continue to remind them on the updated time. If they were already meant to be reminded after the bot restart, it'll remind them instantly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """ | ||
| return await self.find_unique(where={"reminder_id": reminder_id}) | ||
|
|
||
| async def get_unsent_reminders(self) -> list[Reminder]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making changes to db and controller structure this close to a large migration is not advisable. is this necessary?
anemoijereja-eden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great. passes all tests, and works fine in my local test instance.
Suspect IssuesThis pull request was deployed and Sentry observed the following issues: Did you find this useful? React with a 👍 or 👎 |
Description
The
remindmecommand usedtasks.loopto check for reminders, which wasn't ideal. Instead, this PR changes how the remindme works and should be able to send reminders right on time.Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
Ran the remindme command within tux dev bot.
Screenshots (if applicable)
Please add screenshots to help explain your changes.
Additional Information
Please add any other information that is important to this PR.
Summary by Sourcery
Replace periodic polling of reminders with precise scheduling via asyncio.call_later to send reminders on time.
New Features:
Bug Fixes:
Enhancements: