Corrected expired triggers

pull/167/head
bobloy 4 years ago
parent 320f729cc9
commit 796edb4d35

@ -146,14 +146,15 @@ class FIFO(commands.Cog):
await task.delete_self() await task.delete_self()
async def _process_task(self, task: Task): async def _process_task(self, task: Task):
job: Union[Job, None] = await self._get_job(task) # None of this is necessar, we have `replace_existing` already
if job is not None: # job: Union[Job, None] = await self._get_job(task)
combined_trigger_ = await task.get_combined_trigger() # if job is not None:
if combined_trigger_ is None: # combined_trigger_ = await task.get_combined_trigger()
job.remove() # if combined_trigger_ is None:
else: # job.remove()
job.reschedule(combined_trigger_) # else:
return job # job.reschedule(combined_trigger_)
# return job
return await self._add_job(task) return await self._add_job(task)
async def _get_job(self, task: Task) -> Job: async def _get_job(self, task: Task) -> Job:
@ -173,9 +174,10 @@ class FIFO(commands.Cog):
) )
async def _resume_job(self, task: Task): async def _resume_job(self, task: Task):
try: job: Union[Job, None] = await self._get_job(task)
job = self.scheduler.resume_job(job_id=_assemble_job_id(task.name, task.guild_id)) if job is not None:
except JobLookupError: job.resume()
else:
job = await self._process_task(task) job = await self._process_task(task)
return job return job

@ -6,7 +6,6 @@ import discord
from apscheduler.triggers.base import BaseTrigger from apscheduler.triggers.base import BaseTrigger
from apscheduler.triggers.combining import OrTrigger from apscheduler.triggers.combining import OrTrigger
from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.date import DateTrigger
from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.interval import IntervalTrigger
from discord.utils import time_snowflake from discord.utils import time_snowflake
import pytz import pytz
@ -37,7 +36,7 @@ def get_trigger(data):
def check_expired_trigger(trigger: BaseTrigger): 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]): def parse_triggers(data: Union[Dict, None]):

Loading…
Cancel
Save