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