refactor: use a util for script exec

This commit is contained in:
zkldi
2022-07-17 16:17:51 +01:00
parent c25ad6345a
commit b6003f7e87
13 changed files with 71 additions and 113 deletions
@@ -1,5 +1,6 @@
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { WrapScriptPromise } from "utils/misc";
import type { IObjectID } from "monk";
import type { integer } from "tachi-common";
@@ -34,14 +35,6 @@ async function DedupeScoreIDs() {
}
}
DedupeScoreIDs()
.then(() => {
logger.info(`Finished deduping score IDs.`, () => {
process.exit(0);
});
})
.catch((err: unknown) => {
logger.error(`Failed to dedupe score IDs.`, { err }, () => {
process.exit(1);
});
});
if (require.main === module) {
WrapScriptPromise(DedupeScoreIDs(), logger);
}
@@ -1,18 +1,9 @@
import CreateLogCtx from "lib/logger/logger";
import { RecalcAllScores } from "utils/calculations/recalc-scores";
import { WrapScriptPromise } from "utils/misc";
const logger = CreateLogCtx(__filename);
if (require.main === module) {
RecalcAllScores()
.then(() => {
logger.info(`Successfully recalced all scores.`, () => {
process.exit(0);
});
})
.catch((err: unknown) => {
logger.error(`Failed to recalc all scores.`, { err }, () => {
process.exit(1);
});
});
WrapScriptPromise(RecalcAllScores(), logger);
}
@@ -2,6 +2,7 @@
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs";
import { WrapScriptPromise } from "utils/misc";
import { FormatUserDoc } from "utils/user";
import type { Game, Playtype, ScoreDocument } from "tachi-common";
@@ -42,11 +43,5 @@ export async function RecalcGameProfiles() {
}
if (require.main === module) {
RecalcGameProfiles()
.then(() => process.exit(0))
.catch((err: unknown) => {
logger.error(`Failed to recalc game profiles.`, { err }, () => {
process.exit(1);
});
});
WrapScriptPromise(RecalcGameProfiles(), logger);
}
@@ -1,14 +1,9 @@
import CreateLogCtx from "lib/logger/logger";
import { RecalcSessions } from "utils/calculations/recalc-sessions";
import { WrapScriptPromise } from "utils/misc";
const logger = CreateLogCtx(__filename);
if (require.main === module) {
RecalcSessions()
.then(() => process.exit(0))
.catch((err: unknown) => {
logger.error(`Failed to recalc sessions.`, { err }, () => {
process.exit(1);
});
});
WrapScriptPromise(RecalcSessions(), logger);
}
@@ -1,18 +1,10 @@
/* eslint-disable no-await-in-loop */
import CreateLogCtx from "lib/logger/logger";
import { UpdateAllPBs } from "utils/calculations/recalc-scores";
import { WrapScriptPromise } from "utils/misc";
const logger = CreateLogCtx(__filename);
if (require.main === module) {
UpdateAllPBs()
.then(() => {
logger.info(`Successfully updated all PBs.`);
process.exit(0);
})
.catch((err: unknown) => {
logger.error(`Failed to update all PBs.`, { err }, () => {
process.exit(1);
});
});
WrapScriptPromise(UpdateAllPBs(), logger);
}