mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
chore: move saved message clean-up loop with other global loops
This commit is contained in:
parent
394573318d
commit
72d5d9d17a
3 changed files with 17 additions and 15 deletions
|
@ -2,26 +2,11 @@ import { GuildChannel, Message } from "discord.js";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { getRepository, Repository } from "typeorm";
|
||||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||||
import { isAPI } from "../globals";
|
|
||||||
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
||||||
import { MINUTES, SECONDS } from "../utils";
|
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { cleanupMessages } from "./cleanup/messages";
|
|
||||||
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
|
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
|
||||||
import { buildEntity } from "./buildEntity";
|
import { buildEntity } from "./buildEntity";
|
||||||
|
|
||||||
if (!isAPI()) {
|
|
||||||
const CLEANUP_INTERVAL = 5 * MINUTES;
|
|
||||||
|
|
||||||
async function cleanup() {
|
|
||||||
await cleanupMessages();
|
|
||||||
setTimeout(cleanup, CLEANUP_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start first cleanup 30 seconds after startup
|
|
||||||
setTimeout(cleanup, 30 * SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GuildSavedMessages extends BaseGuildRepository {
|
export class GuildSavedMessages extends BaseGuildRepository {
|
||||||
private messages: Repository<SavedMessage>;
|
private messages: Repository<SavedMessage>;
|
||||||
protected toBePermanent: Set<string>;
|
protected toBePermanent: Set<string>;
|
||||||
|
|
14
backend/src/data/loops/savedMessageCleanupLoop.ts
Normal file
14
backend/src/data/loops/savedMessageCleanupLoop.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { MINUTES } from "../../utils";
|
||||||
|
import { cleanupMessages } from "../cleanup/messages";
|
||||||
|
|
||||||
|
const LOOP_INTERVAL = 5 * MINUTES;
|
||||||
|
|
||||||
|
export async function runSavedMessageCleanupLoop() {
|
||||||
|
try {
|
||||||
|
console.log("[SAVED MESSAGE CLEANUP LOOP] Deleting old/deleted messages from the database");
|
||||||
|
const deleted = await cleanupMessages();
|
||||||
|
console.log(`[SAVED MESSAGE CLEANUP LOOP] Deleted ${deleted} old/deleted messages from the database`);
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => runSavedMessageCleanupLoop(), LOOP_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ import { runUpcomingScheduledPostsLoop } from "./data/loops/upcomingScheduledPos
|
||||||
import { runExpiringTempbansLoop } from "./data/loops/expiringTempbansLoop";
|
import { runExpiringTempbansLoop } from "./data/loops/expiringTempbansLoop";
|
||||||
import { runExpiringVCAlertsLoop } from "./data/loops/expiringVCAlertsLoop";
|
import { runExpiringVCAlertsLoop } from "./data/loops/expiringVCAlertsLoop";
|
||||||
import { runExpiredArchiveDeletionLoop } from "./data/loops/expiredArchiveDeletionLoop";
|
import { runExpiredArchiveDeletionLoop } from "./data/loops/expiredArchiveDeletionLoop";
|
||||||
|
import { runSavedMessageCleanupLoop } from "./data/loops/savedMessageCleanupLoop";
|
||||||
|
|
||||||
if (!process.env.KEY) {
|
if (!process.env.KEY) {
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
|
@ -348,6 +349,8 @@ connect().then(async () => {
|
||||||
runExpiringVCAlertsLoop();
|
runExpiringVCAlertsLoop();
|
||||||
await sleep(10 * SECONDS);
|
await sleep(10 * SECONDS);
|
||||||
runExpiredArchiveDeletionLoop();
|
runExpiredArchiveDeletionLoop();
|
||||||
|
await sleep(10 * SECONDS);
|
||||||
|
runSavedMessageCleanupLoop();
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.initialize();
|
bot.initialize();
|
||||||
|
|
Loading…
Add table
Reference in a new issue