fix: closes #12795, don't crash if there is an error in auto approve from queue

This commit is contained in:
Barış Soner Uşaklı
2024-09-14 18:39:22 -04:00
parent c9cadbad7e
commit 6ccf40bf6f

View File

@@ -14,8 +14,12 @@ const slugify = require('../slugify');
const plugins = require('../plugins');
module.exports = function (User) {
new cronJob('0 * * * *', (() => {
User.autoApprove();
new cronJob('0 * * * *', (async () => {
try {
await User.autoApprove();
} catch (err) {
winston.error(err.stack);
}
}), null, true);
User.addToApprovalQueue = async function (userData) {
@@ -160,8 +164,14 @@ module.exports = function (User) {
const users = await db.getSortedSetRevRangeWithScores('registration:queue', 0, -1);
const now = Date.now();
for (const user of users.filter(user => now - user.score >= meta.config.autoApproveTime * 3600000)) {
try {
// eslint-disable-next-line no-await-in-loop
await User.acceptRegistration(user.value);
} catch (err) {
winston.error(err.stack);
// eslint-disable-next-line no-await-in-loop
await removeFromQueue(user.value);
}
}
};
};