Skip to content

Commit

Permalink
clear interval in cache when shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Oct 14, 2024
1 parent 1fb77c4 commit fac9f2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Mjolnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export class Mjolnir {
this.webapis.stop();
this.reportPoller?.stop();
this.openMetrics.stop();
this.moderators.stop();
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/ModCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ModCache {
private managementRoomId: string;
private ttl: number = 1000 * 60 * 60; // 60 minutes
private lastInvalidation = 0;
private interval: any;

constructor(client: MatrixSendClient, emitter: MatrixEmitter, managementRoomId: string) {
this.client = client;
Expand All @@ -38,7 +39,7 @@ export class ModCache {
*/
async init() {
await this.populateCache();
setInterval(
this.interval = setInterval(
() => {
if (Date.now() - this.lastInvalidation > this.ttl) {
this.populateCache();
Expand Down Expand Up @@ -103,4 +104,11 @@ export class ModCache {
public listAll() {
return this.ignoreList.concat(this.modRoomMembers);
}

/**
* Clear the interval which refreshes cache
*/
public stop() {
clearInterval(this.interval);
}
}

0 comments on commit fac9f2d

Please sign in to comment.