Don'Ãt run message cleanup queries in the API process
This commit is contained in:
parent
1ff86defc3
commit
6cd07ed696
3 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { connect } from "../data/db";
|
import { connect } from "../data/db";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { setIsAPI } from "../globals";
|
||||||
|
|
||||||
require("dotenv").config({ path: path.resolve(process.cwd(), "api.env") });
|
require("dotenv").config({ path: path.resolve(process.cwd(), "api.env") });
|
||||||
|
|
||||||
|
@ -10,6 +11,8 @@ function errorHandler(err) {
|
||||||
|
|
||||||
process.on("unhandledRejection", errorHandler);
|
process.on("unhandledRejection", errorHandler);
|
||||||
|
|
||||||
|
setIsAPI(true);
|
||||||
|
|
||||||
// Connect to the database before loading the rest of the code (that depend on the database connection)
|
// Connect to the database before loading the rest of the code (that depend on the database connection)
|
||||||
console.log("Connecting to database..."); // tslint:disable-line
|
console.log("Connecting to database..."); // tslint:disable-line
|
||||||
connect().then(() => {
|
connect().then(() => {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
||||||
import { GuildChannel, Message } from "eris";
|
import { GuildChannel, Message } from "eris";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { DAYS, MINUTES } from "../utils";
|
import { DAYS, MINUTES } from "../utils";
|
||||||
|
import { isAPI } from "../globals";
|
||||||
|
|
||||||
const CLEANUP_INTERVAL = 5 * MINUTES;
|
const CLEANUP_INTERVAL = 5 * MINUTES;
|
||||||
|
|
||||||
|
@ -39,8 +40,10 @@ async function cleanup() {
|
||||||
setTimeout(cleanup, CLEANUP_INTERVAL);
|
setTimeout(cleanup, CLEANUP_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isAPI()) {
|
||||||
// Start first cleanup 30 seconds after startup
|
// Start first cleanup 30 seconds after startup
|
||||||
setTimeout(cleanup, 30 * 1000);
|
setTimeout(cleanup, 30 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
export class GuildSavedMessages extends BaseGuildRepository {
|
export class GuildSavedMessages extends BaseGuildRepository {
|
||||||
private messages: Repository<SavedMessage>;
|
private messages: Repository<SavedMessage>;
|
||||||
|
|
9
backend/src/globals.ts
Normal file
9
backend/src/globals.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
let isAPIValue = false;
|
||||||
|
|
||||||
|
export function isAPI() {
|
||||||
|
return isAPIValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setIsAPI(value: boolean) {
|
||||||
|
isAPIValue = value;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue