3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 15:00:00 +00:00

Attempt another fix for counter decay deadlocks

This commit is contained in:
Dragory 2021-04-14 00:19:39 +03:00
parent a558af1038
commit c26ab2977f
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -12,12 +12,15 @@ import { CounterTriggerState } from "./entities/CounterTriggerState";
import moment from "moment-timezone";
import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils";
import { connection } from "./db";
import { Queue } from "../Queue";
const DELETE_UNUSED_COUNTERS_AFTER = 1 * DAYS;
const DELETE_UNUSED_COUNTER_TRIGGERS_AFTER = 1 * DAYS;
const MAX_COUNTER_VALUE = 2147483647; // 2^31-1, for MySQL INT
const decayQueue = new Queue();
async function deleteCountersMarkedToBeDeleted(): Promise<void> {
await getRepository(Counter)
.createQueryBuilder()
@ -158,7 +161,8 @@ export class GuildCounters extends BaseGuildRepository {
);
}
async decay(id: number, decayPeriodMs: number, decayAmount: number) {
decay(id: number, decayPeriodMs: number, decayAmount: number) {
return decayQueue.add(async () => {
const counter = (await this.counters.findOne({
where: {
id,
@ -205,6 +209,7 @@ export class GuildCounters extends BaseGuildRepository {
last_decay_at: newLastDecayDate,
},
);
});
}
async markUnusedTriggersToBeDeleted(triggerIdsToKeep: number[]) {