Reminders: fix double/triple/etc. posting after reload
This commit is contained in:
parent
a6aacc1998
commit
4cf58bd9f5
1 changed files with 9 additions and 1 deletions
|
@ -27,6 +27,7 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
|
|||
protected tries: Map<number, number>;
|
||||
|
||||
private postRemindersTimeout;
|
||||
private unloaded = false;
|
||||
|
||||
getDefaultOptions(): IPluginOptions<IRemindersPluginConfig> {
|
||||
return {
|
||||
|
@ -51,6 +52,11 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
|
|||
this.postDueRemindersLoop();
|
||||
}
|
||||
|
||||
onUnload() {
|
||||
clearTimeout(this.postRemindersTimeout);
|
||||
this.unloaded = true;
|
||||
}
|
||||
|
||||
async postDueRemindersLoop() {
|
||||
const pendingReminders = await this.reminders.getDueReminders();
|
||||
for (const reminder of pendingReminders) {
|
||||
|
@ -74,7 +80,9 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
|
|||
await this.reminders.delete(reminder.id);
|
||||
}
|
||||
|
||||
this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME);
|
||||
if (!this.unloaded) {
|
||||
this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
@d.command("remind", "<time:string> [reminder:string$]", {
|
||||
|
|
Loading…
Add table
Reference in a new issue