You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On some occasions, a Task using CronTrigger would fire multiple times "at once". As illustrated by my bot log while developing a feature, for cron * * * * *, i.e. minutely:
Note the latter three fires occuring mere miliseconds apart instead of about 60 seconds, and the "duplicated" fires all happening miliseconds earlier than it should be.
Investigation showed that CronTrigger used datetime.now() to find the next fire time, which can cause issues when now() is less than the previously set next fire time, hence the issue. Let's imagine an hourly cron task (0 * * * *):
Action
Normal
Bug
Task start
23:59:31,000
23:59:31,000
Next fire
00:00:00,000
00:00:00,000
Task fire
00:00:00,005
23:59:59,995
Next fire
01:00:00,000
00:00:00,000
In summary, if for some reason the task fires moments before the supposed firing time of XX:00:00,000, CronTrigger's next firing time would fail to advance as it should due to using now() as reference time. This manifests in the task firing multiple times "at once".
Steps to Reproduce
Create and start a interactions.py Task using trigger CronTrigger.
For illustration purposes, the cron in use is * * * * * (every minute when the second ticks zero) and the task just prints the current time.
Expected Results
Task fires once every minute (or as specified by cron) and not more at once.
With said example task, this is shown by the printed current time being always about 60 seconds after the previous.
Replaces the croniter start_time in CronTrigger from `datetime.now()` to `self.last_call_time.astimezone()` to fix a bug causing possible multiple firing.
Fixesinteractions-py#1717
Multiple firing is found to be caused by library bug interactions-py/interactions.py#1717. This fix uses a subclassed CronTrigger, pending library bugfix.
Library Version
5.13.1
Describe the Bug
On some occasions, a
Task
usingCronTrigger
would fire multiple times "at once". As illustrated by my bot log while developing a feature, for cron* * * * *
, i.e. minutely:Note the latter three fires occuring mere miliseconds apart instead of about 60 seconds, and the "duplicated" fires all happening miliseconds earlier than it should be.
Investigation showed that
CronTrigger
useddatetime.now()
to find the next fire time, which can cause issues whennow()
is less than the previously set next fire time, hence the issue. Let's imagine an hourly cron task (0 * * * *
):In summary, if for some reason the task fires moments before the supposed firing time of
XX:00:00,000
,CronTrigger
's next firing time would fail to advance as it should due to usingnow()
as reference time. This manifests in the task firing multiple times "at once".Steps to Reproduce
Create and start a interactions.py
Task
using triggerCronTrigger
.For illustration purposes, the cron in use is
* * * * *
(every minute when the second ticks zero) and the task just prints the current time.Expected Results
Task fires once every minute (or as specified by cron) and not more at once.
With said example task, this is shown by the printed current time being always about 60 seconds after the previous.
Minimal Reproducible Code
Traceback
No response
Checklist
Additional Information
A pull request is being made to fix this issue.
The text was updated successfully, but these errors were encountered: