From 796edb4d355d4498abccebdf2c8472d6283ed06a Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 15 Jan 2021 13:46:37 -0500 Subject: [PATCH] Corrected expired triggers --- fifo/fifo.py | 24 +++++++++++++----------- fifo/task.py | 3 +-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fifo/fifo.py b/fifo/fifo.py index 837caba..89a9e83 100644 --- a/fifo/fifo.py +++ b/fifo/fifo.py @@ -146,14 +146,15 @@ class FIFO(commands.Cog): await task.delete_self() async def _process_task(self, task: Task): - job: Union[Job, None] = await self._get_job(task) - if job is not None: - combined_trigger_ = await task.get_combined_trigger() - if combined_trigger_ is None: - job.remove() - else: - job.reschedule(combined_trigger_) - return job + # None of this is necessar, we have `replace_existing` already + # job: Union[Job, None] = await self._get_job(task) + # if job is not None: + # combined_trigger_ = await task.get_combined_trigger() + # if combined_trigger_ is None: + # job.remove() + # else: + # job.reschedule(combined_trigger_) + # return job return await self._add_job(task) async def _get_job(self, task: Task) -> Job: @@ -173,9 +174,10 @@ class FIFO(commands.Cog): ) async def _resume_job(self, task: Task): - try: - job = self.scheduler.resume_job(job_id=_assemble_job_id(task.name, task.guild_id)) - except JobLookupError: + job: Union[Job, None] = await self._get_job(task) + if job is not None: + job.resume() + else: job = await self._process_task(task) return job diff --git a/fifo/task.py b/fifo/task.py index 53233c4..6f667b9 100644 --- a/fifo/task.py +++ b/fifo/task.py @@ -6,7 +6,6 @@ import discord from apscheduler.triggers.base import BaseTrigger from apscheduler.triggers.combining import OrTrigger from apscheduler.triggers.cron import CronTrigger -from apscheduler.triggers.date import DateTrigger from apscheduler.triggers.interval import IntervalTrigger from discord.utils import time_snowflake import pytz @@ -37,7 +36,7 @@ def get_trigger(data): def check_expired_trigger(trigger: BaseTrigger): - return trigger.get_next_fire_time(None, datetime.now(pytz.utc)) is not None + return trigger.get_next_fire_time(None, datetime.now(pytz.utc)) is None def parse_triggers(data: Union[Dict, None]):