Attempt another fix for counter decay deadlocks
This commit is contained in:
parent
a558af1038
commit
c26ab2977f
1 changed files with 46 additions and 41 deletions
|
@ -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[]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue