Skip to content
Snippets Groups Projects
Commit 4b448b4e authored by Tulir Asokan's avatar Tulir Asokan
Browse files

Use new wrapper for creating background tasks

parent eab7e5d3
No related branches found
No related tags found
No related merge requests found
maubot: 0.1.0 maubot: 0.4.1
id: xyz.maubot.reminder id: xyz.maubot.reminder
version: 0.2.2 version: 0.2.2
license: AGPL-3.0-or-later license: AGPL-3.0-or-later
......
...@@ -23,6 +23,7 @@ import pytz ...@@ -23,6 +23,7 @@ import pytz
from mautrix.types import (EventType, RedactionEvent, StateEvent, Format, MessageType, from mautrix.types import (EventType, RedactionEvent, StateEvent, Format, MessageType,
TextMessageEventContent, ReactionEvent, UserID) TextMessageEventContent, ReactionEvent, UserID)
from mautrix.util.config import BaseProxyConfig from mautrix.util.config import BaseProxyConfig
from mautrix.util import background_task
from maubot import Plugin, MessageEvent from maubot import Plugin, MessageEvent
from maubot.handlers import command, event from maubot.handlers import command, event
...@@ -78,7 +79,7 @@ class ReminderBot(Plugin): ...@@ -78,7 +79,7 @@ class ReminderBot(Plugin):
async def schedule_nearby_reminders(self, now: datetime) -> None: async def schedule_nearby_reminders(self, now: datetime) -> None:
until = now + timedelta(minutes=1) until = now + timedelta(minutes=1)
for reminder in self.db.all_in_range(now, until): for reminder in self.db.all_in_range(now, until):
asyncio.create_task(self.send_reminder(reminder)) background_task.create(self.send_reminder(reminder))
async def send_reminder(self, reminder: ReminderInfo) -> None: async def send_reminder(self, reminder: ReminderInfo) -> None:
try: try:
...@@ -175,7 +176,7 @@ class ReminderBot(Plugin): ...@@ -175,7 +176,7 @@ class ReminderBot(Plugin):
now = datetime.now(tz=pytz.UTC) now = datetime.now(tz=pytz.UTC)
if (rem.date - now).total_seconds() < 60 and now.minute == rem.date.minute: if (rem.date - now).total_seconds() < 60 and now.minute == rem.date.minute:
self.log.debug(f"Reminder {rem} is in less than a minute, scheduling now...") self.log.debug(f"Reminder {rem} is in less than a minute, scheduling now...")
asyncio.create_task(self.send_reminder(rem)) background_task.create(self.send_reminder(rem))
@remind.subcommand("help", help="Usage instructions") @remind.subcommand("help", help="Usage instructions")
async def help(self, evt: MessageEvent) -> None: async def help(self, evt: MessageEvent) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment