Fix stacking scheduled post loop when reloading

This commit is contained in:
Dragory 2019-05-08 08:27:52 +03:00
parent 51b104a096
commit 930296973a

View file

@ -40,6 +40,8 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
protected scheduledPosts: GuildScheduledPosts;
protected logs: GuildLogs;
private scheduledPostLoopTimeout;
onLoad() {
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
this.scheduledPosts = GuildScheduledPosts.getInstance(this.guildId);
@ -48,6 +50,10 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
this.scheduledPostLoop();
}
onUnload() {
clearTimeout(this.scheduledPostLoopTimeout);
}
getDefaultOptions(): IPluginOptions<IPostPluginConfig> {
return {
config: {
@ -183,7 +189,7 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
await this.scheduledPosts.delete(post.id);
}
setTimeout(() => this.scheduledPostLoop(), SCHEDULED_POST_CHECK_INTERVAL);
this.scheduledPostLoopTimeout = setTimeout(() => this.scheduledPostLoop(), SCHEDULED_POST_CHECK_INTERVAL);
}
/**