(sessions): Account for rounding error in expiry.
Also make `_expiry_task` properly cancellable. Fixes an issue where `schedule_expiry` would always reschedule itself.
This commit is contained in:
@@ -61,7 +61,7 @@ class Session:
|
|||||||
raise ValueError("A session for this member already exists!")
|
raise ValueError("A session for this member already exists!")
|
||||||
|
|
||||||
# If the user is study capped, schedule the session start for the next day
|
# If the user is study capped, schedule the session start for the next day
|
||||||
if (lion := Lion.fetch(guildid, userid)).remaining_study_today <= 0:
|
if (lion := Lion.fetch(guildid, userid)).remaining_study_today <= 10:
|
||||||
if pending := cls.members_pending[guildid].pop(userid, None):
|
if pending := cls.members_pending[guildid].pop(userid, None):
|
||||||
pending.cancel()
|
pending.cancel()
|
||||||
task = asyncio.create_task(cls._delayed_start(guildid, userid, member, state))
|
task = asyncio.create_task(cls._delayed_start(guildid, userid, member, state))
|
||||||
@@ -181,12 +181,13 @@ class Session:
|
|||||||
self._expiry_task.cancel()
|
self._expiry_task.cancel()
|
||||||
|
|
||||||
# Wait for the maximum session length
|
# Wait for the maximum session length
|
||||||
|
self._expiry_task = asyncio.create_task(asyncio.sleep(self.lion.remaining_study_today))
|
||||||
try:
|
try:
|
||||||
self._expiry_task = await asyncio.sleep(self.lion.remaining_study_today)
|
await self._expiry_task
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if self.lion.remaining_study_today <= 0:
|
if self.lion.remaining_study_today <= 10:
|
||||||
# End the session
|
# End the session
|
||||||
# Note that the user will not automatically start a new session when the day starts
|
# Note that the user will not automatically start a new session when the day starts
|
||||||
# TODO: Notify user? Disconnect them?
|
# TODO: Notify user? Disconnect them?
|
||||||
|
|||||||
Reference in New Issue
Block a user