aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-06-04 18:50:39 -0700
committerGravatar GitHub <[email protected]>2021-06-04 18:50:39 -0700
commit9ef426f145a2552167737cddb83ed0f3c7334eeb (patch)
tree22e3d6c4e5b1368336bf03782f1837013976e58c
parentfeat: add async-await tag (#1594) (diff)
parentMerge branch 'main' into bast0006-infraction-scheduler-fix (diff)
Merge pull request #1609 from bast0006/bast0006-infraction-scheduler-fix
Fix infraction rescheduler breaking with more than 100 in flight reactions
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 988fb7220..8286d3635 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -47,12 +47,33 @@ class InfractionScheduler:
log.trace(f"Rescheduling infractions for {self.__class__.__name__}.")
infractions = await self.bot.api_client.get(
- 'bot/infractions',
- params={'active': 'true'}
+ "bot/infractions",
+ params={
+ "active": "true",
+ "ordering": "expires_at",
+ "permanent": "false",
+ "types": ",".join(supported_infractions),
+ },
)
- for infraction in infractions:
- if infraction["expires_at"] is not None and infraction["type"] in supported_infractions:
- self.schedule_expiration(infraction)
+
+ to_schedule = [i for i in infractions if i["id"] not in self.scheduler]
+
+ for infraction in to_schedule:
+ log.trace("Scheduling %r", infraction)
+ self.schedule_expiration(infraction)
+
+ # Call ourselves again when the last infraction would expire. This will be the "oldest" infraction we've seen
+ # from the database so far, and new ones are scheduled as part of application.
+ # We make sure to fire this
+ if to_schedule:
+ next_reschedule_point = max(
+ dateutil.parser.isoparse(infr["expires_at"]).replace(tzinfo=None) for infr in to_schedule
+ )
+ log.trace("Will reschedule remaining infractions at %s", next_reschedule_point)
+
+ self.scheduler.schedule_at(next_reschedule_point, -1, self.reschedule_infractions(supported_infractions))
+
+ log.trace("Done rescheduling")
async def reapply_infraction(
self,