Reminders: fix double/triple/etc. posting after reload

This commit is contained in:
Dragory 2019-07-12 14:21:25 +03:00
parent a6aacc1998
commit 4cf58bd9f5

View file

@ -27,6 +27,7 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
protected tries: Map<number, number>; protected tries: Map<number, number>;
private postRemindersTimeout; private postRemindersTimeout;
private unloaded = false;
getDefaultOptions(): IPluginOptions<IRemindersPluginConfig> { getDefaultOptions(): IPluginOptions<IRemindersPluginConfig> {
return { return {
@ -51,6 +52,11 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
this.postDueRemindersLoop(); this.postDueRemindersLoop();
} }
onUnload() {
clearTimeout(this.postRemindersTimeout);
this.unloaded = true;
}
async postDueRemindersLoop() { async postDueRemindersLoop() {
const pendingReminders = await this.reminders.getDueReminders(); const pendingReminders = await this.reminders.getDueReminders();
for (const reminder of pendingReminders) { for (const reminder of pendingReminders) {
@ -74,7 +80,9 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
await this.reminders.delete(reminder.id); 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$]", { @d.command("remind", "<time:string> [reminder:string$]", {